@codemem/core 0.20.5-alpha.2 → 0.20.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +417 -409
- package/dist/index.js.map +1 -1
- package/dist/observer-client.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5355,7 +5355,21 @@ function Us(e) {
|
|
|
5355
5355
|
"content-type": "application/json"
|
|
5356
5356
|
};
|
|
5357
5357
|
}
|
|
5358
|
-
function Ws(e, t
|
|
5358
|
+
function Ws(e, t) {
|
|
5359
|
+
let n = { ...e };
|
|
5360
|
+
for (let [e, r] of Object.entries(t)) {
|
|
5361
|
+
let t = e.toLowerCase();
|
|
5362
|
+
for (let e of Object.keys(n)) e.toLowerCase() === t && delete n[e];
|
|
5363
|
+
n[e] = r;
|
|
5364
|
+
}
|
|
5365
|
+
return n;
|
|
5366
|
+
}
|
|
5367
|
+
function Gs(e, t) {
|
|
5368
|
+
let n = Ws(e, t);
|
|
5369
|
+
for (let t of Object.keys(e)) delete e[t];
|
|
5370
|
+
Object.assign(e, n);
|
|
5371
|
+
}
|
|
5372
|
+
function Ks(e, t, n, r) {
|
|
5359
5373
|
return {
|
|
5360
5374
|
model: e,
|
|
5361
5375
|
max_tokens: r,
|
|
@@ -5369,7 +5383,7 @@ function Ws(e, t, n, r) {
|
|
|
5369
5383
|
}]
|
|
5370
5384
|
};
|
|
5371
5385
|
}
|
|
5372
|
-
function
|
|
5386
|
+
function qs(e) {
|
|
5373
5387
|
let t = e.choices;
|
|
5374
5388
|
if (!Array.isArray(t) || t.length === 0) return null;
|
|
5375
5389
|
let n = t[0];
|
|
@@ -5379,10 +5393,10 @@ function Gs(e) {
|
|
|
5379
5393
|
let i = r.content;
|
|
5380
5394
|
return typeof i == "string" ? i : null;
|
|
5381
5395
|
}
|
|
5382
|
-
function
|
|
5396
|
+
function Js() {
|
|
5383
5397
|
return process.env.CODEMEM_CODEX_ENDPOINT ?? ks;
|
|
5384
5398
|
}
|
|
5385
|
-
function
|
|
5399
|
+
function Ys(e, t) {
|
|
5386
5400
|
return {
|
|
5387
5401
|
model: e,
|
|
5388
5402
|
instructions: "You are a memory observer.",
|
|
@@ -5397,7 +5411,7 @@ function qs(e, t) {
|
|
|
5397
5411
|
stream: !0
|
|
5398
5412
|
};
|
|
5399
5413
|
}
|
|
5400
|
-
function
|
|
5414
|
+
function Xs(e, t) {
|
|
5401
5415
|
let n = [];
|
|
5402
5416
|
for (let r of e.split("\n")) {
|
|
5403
5417
|
if (!r.startsWith("data:")) continue;
|
|
@@ -5409,14 +5423,14 @@ function Js(e, t) {
|
|
|
5409
5423
|
}
|
|
5410
5424
|
return n.length > 0 ? n.join("").trim() : null;
|
|
5411
5425
|
}
|
|
5412
|
-
function
|
|
5426
|
+
function Zs(e) {
|
|
5413
5427
|
if (e.type === "response.output_text.delta") {
|
|
5414
5428
|
let t = e.delta;
|
|
5415
5429
|
return typeof t == "string" && t ? t : null;
|
|
5416
5430
|
}
|
|
5417
5431
|
return null;
|
|
5418
5432
|
}
|
|
5419
|
-
function
|
|
5433
|
+
function Qs(e) {
|
|
5420
5434
|
if (e.type === "content_block_delta") {
|
|
5421
5435
|
let t = e.delta;
|
|
5422
5436
|
if (t && t.type === "text_delta") {
|
|
@@ -5426,10 +5440,10 @@ function Xs(e) {
|
|
|
5426
5440
|
}
|
|
5427
5441
|
return null;
|
|
5428
5442
|
}
|
|
5429
|
-
function
|
|
5443
|
+
function $s() {
|
|
5430
5444
|
return Date.now();
|
|
5431
5445
|
}
|
|
5432
|
-
var
|
|
5446
|
+
var ec = class {
|
|
5433
5447
|
provider;
|
|
5434
5448
|
model;
|
|
5435
5449
|
runtime;
|
|
@@ -5500,7 +5514,7 @@ var Qs = class {
|
|
|
5500
5514
|
let e = await this._callOnce(a, s);
|
|
5501
5515
|
return e && this._clearLastError(), {
|
|
5502
5516
|
raw: e,
|
|
5503
|
-
parsed: e ?
|
|
5517
|
+
parsed: e ? nc(e) : null,
|
|
5504
5518
|
provider: this.provider,
|
|
5505
5519
|
model: this.model
|
|
5506
5520
|
};
|
|
@@ -5511,7 +5525,7 @@ var Qs = class {
|
|
|
5511
5525
|
let e = await this._callOnce(a, s);
|
|
5512
5526
|
return e && this._clearLastError(), {
|
|
5513
5527
|
raw: e,
|
|
5514
|
-
parsed: e ?
|
|
5528
|
+
parsed: e ? nc(e) : null,
|
|
5515
5529
|
provider: this.provider,
|
|
5516
5530
|
model: this.model
|
|
5517
5531
|
};
|
|
@@ -5528,7 +5542,7 @@ var Qs = class {
|
|
|
5528
5542
|
if (this.provider === "openai" || this.provider === "anthropic") {
|
|
5529
5543
|
r = cs(this.provider, this.model), n = us(t, r);
|
|
5530
5544
|
let e = ms(t, r);
|
|
5531
|
-
n && e != null && e <=
|
|
5545
|
+
n && e != null && e <= $s() && (n = null);
|
|
5532
5546
|
}
|
|
5533
5547
|
if (this.provider !== "openai" && this.provider !== "anthropic") {
|
|
5534
5548
|
let n = at(this.provider), [r, i, a] = Object.keys(n).length > 0 ? Ct(this.provider, this.model) : pt(this.provider, this.model);
|
|
@@ -5564,15 +5578,12 @@ var Qs = class {
|
|
|
5564
5578
|
if (!this.auth.token) {
|
|
5565
5579
|
if (this._initProvider(!0), this._codexAccess) return this._callCodexConsumer(t);
|
|
5566
5580
|
if (this._anthropicOAuthAccess) return this._callAnthropicConsumer(e, t);
|
|
5567
|
-
if (!this.auth.token) return this._setLastError(`${
|
|
5581
|
+
if (!this.auth.token) return this._setLastError(`${tc(this.provider)} credentials are missing.`, "auth_missing"), null;
|
|
5568
5582
|
}
|
|
5569
5583
|
return this.provider === "anthropic" ? this._callAnthropicDirect(e, t) : this._callOpenAIDirect(e, t);
|
|
5570
5584
|
}
|
|
5571
5585
|
async _callAnthropicDirect(e, t) {
|
|
5572
|
-
let n = zs(), r =
|
|
5573
|
-
...Bs(this.auth.token ?? "", !1),
|
|
5574
|
-
...ws(this._observerHeaders, this.auth)
|
|
5575
|
-
}, i = Vs(this.model, e, t, this.maxTokens);
|
|
5586
|
+
let n = zs(), r = Ws(Bs(this.auth.token ?? "", !1), ws(this._observerHeaders, this.auth)), i = Vs(this.model, e, t, this.maxTokens);
|
|
5576
5587
|
return this._fetchJSON(n, r, i, {
|
|
5577
5588
|
parseResponse: Hs,
|
|
5578
5589
|
providerLabel: "Anthropic"
|
|
@@ -5581,13 +5592,10 @@ var Qs = class {
|
|
|
5581
5592
|
async _callOpenAIDirect(e, t) {
|
|
5582
5593
|
let n;
|
|
5583
5594
|
n = this._customBaseUrl ? `${this._customBaseUrl.replace(/\/+$/, "")}/chat/completions` : "https://api.openai.com/v1/chat/completions";
|
|
5584
|
-
let r =
|
|
5585
|
-
...Us(this.auth.token ?? ""),
|
|
5586
|
-
...ws(this._observerHeaders, this.auth)
|
|
5587
|
-
}, i = Ws(this.model, e, t, this.maxTokens);
|
|
5595
|
+
let r = Ws(Us(this.auth.token ?? ""), ws(this._observerHeaders, this.auth)), i = Ks(this.model, e, t, this.maxTokens);
|
|
5588
5596
|
return this._fetchJSON(n, r, i, {
|
|
5589
|
-
parseResponse:
|
|
5590
|
-
providerLabel:
|
|
5597
|
+
parseResponse: qs,
|
|
5598
|
+
providerLabel: tc(this.provider)
|
|
5591
5599
|
});
|
|
5592
5600
|
}
|
|
5593
5601
|
async _callCodexConsumer(e) {
|
|
@@ -5599,11 +5607,11 @@ var Qs = class {
|
|
|
5599
5607
|
authType: "bearer",
|
|
5600
5608
|
source: this.auth.source
|
|
5601
5609
|
};
|
|
5602
|
-
|
|
5610
|
+
Gs(t, ws(this._observerHeaders, e));
|
|
5603
5611
|
}
|
|
5604
5612
|
t["content-type"] = "application/json";
|
|
5605
|
-
let n =
|
|
5606
|
-
return this._fetchSSE(r, t, n,
|
|
5613
|
+
let n = Ys(this.model, e), r = Js();
|
|
5614
|
+
return this._fetchSSE(r, t, n, Zs, {
|
|
5607
5615
|
providerLabel: "OpenAI",
|
|
5608
5616
|
authErrorMessage: "OpenAI authentication failed. Refresh credentials and retry."
|
|
5609
5617
|
});
|
|
@@ -5617,7 +5625,7 @@ var Qs = class {
|
|
|
5617
5625
|
authType: "bearer",
|
|
5618
5626
|
source: this.auth.source
|
|
5619
5627
|
};
|
|
5620
|
-
|
|
5628
|
+
Gs(n, ws(this._observerHeaders, e));
|
|
5621
5629
|
}
|
|
5622
5630
|
let r = zs(), i = new URL(r);
|
|
5623
5631
|
i.searchParams.set("beta", "true");
|
|
@@ -5631,7 +5639,7 @@ var Qs = class {
|
|
|
5631
5639
|
}],
|
|
5632
5640
|
system: e
|
|
5633
5641
|
};
|
|
5634
|
-
return this._fetchSSE(a, n, o,
|
|
5642
|
+
return this._fetchSSE(a, n, o, Qs, {
|
|
5635
5643
|
providerLabel: "Anthropic",
|
|
5636
5644
|
authErrorMessage: "Anthropic authentication failed. Refresh credentials and retry."
|
|
5637
5645
|
});
|
|
@@ -5667,7 +5675,7 @@ var Qs = class {
|
|
|
5667
5675
|
if (await a.text().catch(() => ""), Ls(a.status)) throw this._setLastError(i.authErrorMessage, "auth_failed"), new Is(`${i.providerLabel} auth error: ${a.status}`);
|
|
5668
5676
|
return this._setLastError(`${i.providerLabel} request failed during observer processing.`, "provider_request_failed"), null;
|
|
5669
5677
|
}
|
|
5670
|
-
return
|
|
5678
|
+
return Xs(await a.text(), r);
|
|
5671
5679
|
} catch (e) {
|
|
5672
5680
|
if (e instanceof Is) throw e;
|
|
5673
5681
|
return this._setLastError(`${i.providerLabel} processing failed during observer inference.`, "observer_call_failed"), null;
|
|
@@ -5700,10 +5708,10 @@ var Qs = class {
|
|
|
5700
5708
|
this._lastErrorCode = null, this._lastErrorMessage = null;
|
|
5701
5709
|
}
|
|
5702
5710
|
};
|
|
5703
|
-
function
|
|
5711
|
+
function tc(e) {
|
|
5704
5712
|
return e.charAt(0).toUpperCase() + e.slice(1);
|
|
5705
5713
|
}
|
|
5706
|
-
function
|
|
5714
|
+
function nc(e) {
|
|
5707
5715
|
try {
|
|
5708
5716
|
let t = JSON.parse(e);
|
|
5709
5717
|
return typeof t == "object" && t && !Array.isArray(t) ? t : null;
|
|
@@ -5713,10 +5721,10 @@ function ec(e) {
|
|
|
5713
5721
|
}
|
|
5714
5722
|
//#endregion
|
|
5715
5723
|
//#region src/search.ts
|
|
5716
|
-
function
|
|
5724
|
+
function rc(e) {
|
|
5717
5725
|
return N(e, { schema: H });
|
|
5718
5726
|
}
|
|
5719
|
-
var
|
|
5727
|
+
var ic = {
|
|
5720
5728
|
session_summary: .25,
|
|
5721
5729
|
decision: .2,
|
|
5722
5730
|
feature: .18,
|
|
@@ -5728,32 +5736,32 @@ var nc = {
|
|
|
5728
5736
|
observation: .1,
|
|
5729
5737
|
exploration: .1,
|
|
5730
5738
|
entities: .05
|
|
5731
|
-
},
|
|
5739
|
+
}, ac = .45, oc = .18, sc = .12, cc = 3, lc = 0, uc = 2, dc = [
|
|
5732
5740
|
/\bwhat did i\b/i,
|
|
5733
5741
|
/\bmy notes\b/i,
|
|
5734
5742
|
/\bmy last session\b/i,
|
|
5735
5743
|
/\bmy machine\b/i
|
|
5736
|
-
],
|
|
5744
|
+
], fc = new Set([
|
|
5737
5745
|
"or",
|
|
5738
5746
|
"and",
|
|
5739
5747
|
"not",
|
|
5740
5748
|
"near",
|
|
5741
5749
|
"phrase"
|
|
5742
5750
|
]);
|
|
5743
|
-
function
|
|
5751
|
+
function pc(e) {
|
|
5744
5752
|
let t = e.match(/[A-Za-z0-9_]+/g);
|
|
5745
5753
|
if (!t) return "";
|
|
5746
|
-
let n = t.filter((e) => !
|
|
5754
|
+
let n = t.filter((e) => !fc.has(e.toLowerCase()));
|
|
5747
5755
|
return n.length === 0 ? "" : n.length === 1 ? n[0] : n.join(" OR ");
|
|
5748
5756
|
}
|
|
5749
|
-
function
|
|
5757
|
+
function mc(e, t) {
|
|
5750
5758
|
let n = Date.parse(e);
|
|
5751
5759
|
return Number.isNaN(n) ? 0 : 1 / (1 + Math.max(0, Math.floor(((t ?? /* @__PURE__ */ new Date()).getTime() - n) / 864e5)) / 7);
|
|
5752
5760
|
}
|
|
5753
|
-
function
|
|
5754
|
-
return e ?
|
|
5761
|
+
function hc(e) {
|
|
5762
|
+
return e ? ic[e.trim().toLowerCase()] ?? 0 : 0;
|
|
5755
5763
|
}
|
|
5756
|
-
function
|
|
5764
|
+
function gc(e) {
|
|
5757
5765
|
if (!e || e.personal_first === void 0) return !0;
|
|
5758
5766
|
let t = e.personal_first;
|
|
5759
5767
|
if (typeof t == "string") {
|
|
@@ -5773,10 +5781,10 @@ function mc(e) {
|
|
|
5773
5781
|
}
|
|
5774
5782
|
return !!t;
|
|
5775
5783
|
}
|
|
5776
|
-
function
|
|
5784
|
+
function _c(e) {
|
|
5777
5785
|
return String(e?.trust_bias ?? "off").trim().toLowerCase() === "soft" ? "soft" : "off";
|
|
5778
5786
|
}
|
|
5779
|
-
function
|
|
5787
|
+
function vc(e) {
|
|
5780
5788
|
if (!e || e.widen_shared_when_weak === void 0) return !1;
|
|
5781
5789
|
let t = e.widen_shared_when_weak;
|
|
5782
5790
|
if (typeof t == "string") {
|
|
@@ -5796,25 +5804,25 @@ function gc(e) {
|
|
|
5796
5804
|
}
|
|
5797
5805
|
return !!t;
|
|
5798
5806
|
}
|
|
5799
|
-
function
|
|
5807
|
+
function yc(e) {
|
|
5800
5808
|
let t = e?.widen_shared_min_personal_results;
|
|
5801
|
-
return typeof t != "number" || !Number.isFinite(t) ?
|
|
5809
|
+
return typeof t != "number" || !Number.isFinite(t) ? cc : Math.max(1, Math.trunc(t));
|
|
5802
5810
|
}
|
|
5803
|
-
function
|
|
5811
|
+
function bc(e) {
|
|
5804
5812
|
let t = e?.widen_shared_min_personal_score;
|
|
5805
|
-
return typeof t != "number" || !Number.isFinite(t) ?
|
|
5813
|
+
return typeof t != "number" || !Number.isFinite(t) ? lc : Math.max(0, t);
|
|
5806
5814
|
}
|
|
5807
|
-
function
|
|
5808
|
-
return
|
|
5815
|
+
function xc(e) {
|
|
5816
|
+
return dc.some((t) => t.test(e));
|
|
5809
5817
|
}
|
|
5810
|
-
function
|
|
5818
|
+
function Sc(e) {
|
|
5811
5819
|
if (!e) return !1;
|
|
5812
5820
|
let t = String(e.ownership_scope ?? "").trim().toLowerCase();
|
|
5813
5821
|
if (t === "mine" || t === "theirs") return !0;
|
|
5814
5822
|
let n = Ta(e.include_visibility ?? e.visibility), r = Ta(e.exclude_visibility), i = Ca(e.include_workspace_ids), a = Ca(e.exclude_workspace_ids), o = wa(e.include_workspace_kinds), s = wa(e.exclude_workspace_kinds);
|
|
5815
5823
|
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:"));
|
|
5816
5824
|
}
|
|
5817
|
-
function
|
|
5825
|
+
function Cc(e) {
|
|
5818
5826
|
return {
|
|
5819
5827
|
...e ?? {},
|
|
5820
5828
|
visibility: void 0,
|
|
@@ -5825,7 +5833,7 @@ function xc(e) {
|
|
|
5825
5833
|
widen_shared_when_weak: !1
|
|
5826
5834
|
};
|
|
5827
5835
|
}
|
|
5828
|
-
function
|
|
5836
|
+
function wc(e) {
|
|
5829
5837
|
return e.map((e) => ({
|
|
5830
5838
|
...e,
|
|
5831
5839
|
metadata: {
|
|
@@ -5834,83 +5842,83 @@ function Sc(e) {
|
|
|
5834
5842
|
}
|
|
5835
5843
|
}));
|
|
5836
5844
|
}
|
|
5837
|
-
function
|
|
5838
|
-
return
|
|
5845
|
+
function Tc(e, t, n) {
|
|
5846
|
+
return gc(n) && e.memoryOwnedBySelf(t) ? ac : 0;
|
|
5839
5847
|
}
|
|
5840
|
-
function
|
|
5841
|
-
if (
|
|
5848
|
+
function Ec(e, t, n) {
|
|
5849
|
+
if (_c(n) !== "soft" || e.memoryOwnedBySelf(t)) return 0;
|
|
5842
5850
|
let r = t.metadata ?? {}, i = String(r.visibility ?? "").trim().toLowerCase(), a = String(r.workspace_kind ?? "").trim().toLowerCase();
|
|
5843
5851
|
if (i !== "shared" && a !== "shared") return 0;
|
|
5844
5852
|
let o = String(r.trust_state ?? "trusted").trim().toLowerCase();
|
|
5845
|
-
return o === "legacy_unknown" ?
|
|
5853
|
+
return o === "legacy_unknown" ? oc : o === "unreviewed" ? sc : 0;
|
|
5846
5854
|
}
|
|
5847
|
-
function
|
|
5855
|
+
function Dc(e) {
|
|
5848
5856
|
let t = e.trim().replaceAll("\\", "/");
|
|
5849
5857
|
t.startsWith("./") && (t = t.slice(2));
|
|
5850
5858
|
let n = t.split("/").filter((e) => e && e !== ".");
|
|
5851
5859
|
return n.length === 0 ? "" : n.join("/").toLowerCase();
|
|
5852
5860
|
}
|
|
5853
|
-
function
|
|
5854
|
-
let t =
|
|
5861
|
+
function Oc(e) {
|
|
5862
|
+
let t = Dc(e);
|
|
5855
5863
|
return t ? t.split("/") : [];
|
|
5856
5864
|
}
|
|
5857
|
-
function
|
|
5858
|
-
let t =
|
|
5865
|
+
function kc(e) {
|
|
5866
|
+
let t = Oc(e);
|
|
5859
5867
|
return t.length === 0 ? "" : t[t.length - 1] ?? "";
|
|
5860
5868
|
}
|
|
5861
|
-
function
|
|
5869
|
+
function Ac(e, t) {
|
|
5862
5870
|
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("/");
|
|
5863
5871
|
}
|
|
5864
|
-
function
|
|
5872
|
+
function jc(e) {
|
|
5865
5873
|
if (!Array.isArray(e)) return [];
|
|
5866
5874
|
let t = [], n = /* @__PURE__ */ new Set();
|
|
5867
5875
|
for (let r of e) {
|
|
5868
5876
|
if (typeof r != "string") continue;
|
|
5869
|
-
let e =
|
|
5877
|
+
let e = Dc(r);
|
|
5870
5878
|
!e || n.has(e) || (n.add(e), t.push(e));
|
|
5871
5879
|
}
|
|
5872
5880
|
return t;
|
|
5873
5881
|
}
|
|
5874
|
-
function
|
|
5882
|
+
function Mc(e) {
|
|
5875
5883
|
let t = (e.metadata ?? {}).files_modified;
|
|
5876
5884
|
if (!Array.isArray(t)) return [];
|
|
5877
5885
|
let n = [];
|
|
5878
5886
|
for (let e of t) {
|
|
5879
5887
|
if (typeof e != "string") continue;
|
|
5880
|
-
let t =
|
|
5888
|
+
let t = Dc(e);
|
|
5881
5889
|
t && n.push(t);
|
|
5882
5890
|
}
|
|
5883
5891
|
return n;
|
|
5884
5892
|
}
|
|
5885
|
-
function
|
|
5893
|
+
function Nc(e, t) {
|
|
5886
5894
|
if (t.length === 0) return 0;
|
|
5887
|
-
let n =
|
|
5895
|
+
let n = Mc(e);
|
|
5888
5896
|
if (n.length === 0) return 0;
|
|
5889
|
-
let r = [...new Set(n)].map((e) =>
|
|
5890
|
-
for (let e of r) i.some((t) =>
|
|
5897
|
+
let r = [...new Set(n)].map((e) => Oc(e)), i = [...new Set(t)].map((e) => Oc(e)), a = new Set(n.map((e) => kc(e)).filter(Boolean)), o = new Set(t.map((e) => kc(e)).filter(Boolean)), s = 0;
|
|
5898
|
+
for (let e of r) i.some((t) => Ac(e, t)) && (s += 1);
|
|
5891
5899
|
let c = 0;
|
|
5892
5900
|
for (let e of a) o.has(e) && (c += 1);
|
|
5893
5901
|
let l = s * .16 + c * .06;
|
|
5894
5902
|
return Math.min(.32, l);
|
|
5895
5903
|
}
|
|
5896
|
-
function
|
|
5897
|
-
let i = /* @__PURE__ */ new Date(), a =
|
|
5904
|
+
function Pc(e, t, n, r) {
|
|
5905
|
+
let i = /* @__PURE__ */ new Date(), a = jc(r?.working_set_paths), o = t.map((t) => ({
|
|
5898
5906
|
item: t,
|
|
5899
|
-
combinedScore: t.score * 1.5 +
|
|
5907
|
+
combinedScore: t.score * 1.5 + mc(t.created_at, i) + hc(t.kind) + Nc(t, a) + Tc(e, t, r) - Ec(e, t, r)
|
|
5900
5908
|
}));
|
|
5901
5909
|
return o.sort((e, t) => t.combinedScore - e.combinedScore), o.slice(0, n).map((e) => e.item);
|
|
5902
5910
|
}
|
|
5903
|
-
function
|
|
5904
|
-
let i =
|
|
5905
|
-
if (!
|
|
5911
|
+
function Fc(e, t, n = 10, r) {
|
|
5912
|
+
let i = Ic(e, t, n, r);
|
|
5913
|
+
if (!vc(r) || !t || xc(t) || Sc(r)) return i;
|
|
5906
5914
|
let a = i.filter((t) => e.memoryOwnedBySelf(t)), o = a[0]?.score ?? -Infinity;
|
|
5907
|
-
if (a.length >=
|
|
5908
|
-
let s =
|
|
5909
|
-
for (let e of s) if (!c.has(e.id) && (c.add(e.id), l.push(e), u += 1, u >=
|
|
5915
|
+
if (a.length >= yc(r) && o >= bc(r)) return i;
|
|
5916
|
+
let s = wc(Ic(e, t, uc, Cc(r)).filter((t) => !e.memoryOwnedBySelf(t))), c = new Set(i.map((e) => e.id)), l = [...i], u = 0;
|
|
5917
|
+
for (let e of s) if (!c.has(e.id) && (c.add(e.id), l.push(e), u += 1, u >= uc)) break;
|
|
5910
5918
|
return l;
|
|
5911
5919
|
}
|
|
5912
|
-
function
|
|
5913
|
-
let i = Math.max(1, Math.trunc(n)), a =
|
|
5920
|
+
function Ic(e, t, n = 10, r) {
|
|
5921
|
+
let i = Math.max(1, Math.trunc(n)), a = pc(t);
|
|
5914
5922
|
if (!a) return [];
|
|
5915
5923
|
let o = Math.min(Math.max(i * 4, i + 8), 200), s = [a], c = ["memory_items.active = 1", "memory_fts MATCH ?"], l = ka(r, {
|
|
5916
5924
|
actorId: e.actorId,
|
|
@@ -5928,7 +5936,7 @@ function Pc(e, t, n = 10, r) {
|
|
|
5928
5936
|
ORDER BY (score * 1.5 + recency) DESC, memory_items.created_at DESC, memory_items.id DESC
|
|
5929
5937
|
LIMIT ?
|
|
5930
5938
|
`;
|
|
5931
|
-
return s.push(o),
|
|
5939
|
+
return s.push(o), Pc(e, e.db.prepare(d).all(...s).map((e) => {
|
|
5932
5940
|
let t = { ...z(e.metadata_json) };
|
|
5933
5941
|
for (let n of [
|
|
5934
5942
|
"actor_id",
|
|
@@ -5962,7 +5970,7 @@ function Pc(e, t, n = 10, r) {
|
|
|
5962
5970
|
};
|
|
5963
5971
|
}), i, r);
|
|
5964
5972
|
}
|
|
5965
|
-
function
|
|
5973
|
+
function Lc(e, t, n, r = 3, i = 3, a) {
|
|
5966
5974
|
let o = null;
|
|
5967
5975
|
if (n != null) {
|
|
5968
5976
|
let t = e.get(n);
|
|
@@ -5973,7 +5981,7 @@ function Fc(e, t, n, r = 3, i = 3, a) {
|
|
|
5973
5981
|
});
|
|
5974
5982
|
}
|
|
5975
5983
|
if (o == null && t) {
|
|
5976
|
-
let n =
|
|
5984
|
+
let n = Fc(e, t, 1, a ?? void 0);
|
|
5977
5985
|
if (n.length > 0) {
|
|
5978
5986
|
let e = n[0];
|
|
5979
5987
|
o = {
|
|
@@ -5983,9 +5991,9 @@ function Fc(e, t, n, r = 3, i = 3, a) {
|
|
|
5983
5991
|
};
|
|
5984
5992
|
}
|
|
5985
5993
|
}
|
|
5986
|
-
return o == null ? [] :
|
|
5994
|
+
return o == null ? [] : Rc(e, o, r, i, a);
|
|
5987
5995
|
}
|
|
5988
|
-
function
|
|
5996
|
+
function Rc(e, t, n, r, i) {
|
|
5989
5997
|
let a = t.id, o = t.created_at, s = t.session_id;
|
|
5990
5998
|
if (!a || !o) return [];
|
|
5991
5999
|
let c = ka(i, {
|
|
@@ -6003,7 +6011,7 @@ function Ic(e, t, n, r, i) {
|
|
|
6003
6011
|
${f}
|
|
6004
6012
|
WHERE ${d} AND memory_items.created_at > ?
|
|
6005
6013
|
ORDER BY memory_items.created_at ASC
|
|
6006
|
-
LIMIT ?`).all(...u, o, r), h =
|
|
6014
|
+
LIMIT ?`).all(...u, o, r), h = rc(e.db).select().from(W).where(D(k(W.id, a), k(W.active, 1))).get(), g = [...p.reverse()];
|
|
6007
6015
|
return h && g.push(h), g.push(...m), g.map((e) => {
|
|
6008
6016
|
let { metadata_json: t, ...n } = e;
|
|
6009
6017
|
return {
|
|
@@ -6013,7 +6021,7 @@ function Ic(e, t, n, r, i) {
|
|
|
6013
6021
|
};
|
|
6014
6022
|
});
|
|
6015
6023
|
}
|
|
6016
|
-
function
|
|
6024
|
+
function zc(e) {
|
|
6017
6025
|
let t = /* @__PURE__ */ new Set(), n = [], r = [];
|
|
6018
6026
|
for (let i of e) {
|
|
6019
6027
|
let e = ts(i);
|
|
@@ -6028,8 +6036,8 @@ function Lc(e) {
|
|
|
6028
6036
|
invalid: r
|
|
6029
6037
|
};
|
|
6030
6038
|
}
|
|
6031
|
-
function
|
|
6032
|
-
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 =
|
|
6039
|
+
function Bc(e, t, n, r, i, a, o, s) {
|
|
6040
|
+
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 = mc(e.created_at, s), f = hc(e.kind), p = null;
|
|
6033
6041
|
return u != null && (p = u * 1.5 + d + f), {
|
|
6034
6042
|
id: e.id,
|
|
6035
6043
|
kind: e.kind,
|
|
@@ -6060,14 +6068,14 @@ function Rc(e, t, n, r, i, a, o, s) {
|
|
|
6060
6068
|
} : null
|
|
6061
6069
|
};
|
|
6062
6070
|
}
|
|
6063
|
-
function
|
|
6071
|
+
function Vc(e, t, n) {
|
|
6064
6072
|
if (t.length === 0) return {
|
|
6065
6073
|
items: [],
|
|
6066
6074
|
missingNotFound: [],
|
|
6067
6075
|
missingProjectMismatch: [],
|
|
6068
6076
|
missingFilterMismatch: []
|
|
6069
6077
|
};
|
|
6070
|
-
let r =
|
|
6078
|
+
let r = rc(e.db).select().from(W).where(D(k(W.active, 1), j(W.id, t))).all(), i = new Set(r.map((e) => e.id)), a = t.map(() => "?").join(", "), o = r, s = new Set(i);
|
|
6071
6079
|
if (n.project) {
|
|
6072
6080
|
let r = ka({ project: n.project }, {
|
|
6073
6081
|
actorId: e.actorId,
|
|
@@ -6113,16 +6121,16 @@ function zc(e, t, n) {
|
|
|
6113
6121
|
missingFilterMismatch: m
|
|
6114
6122
|
};
|
|
6115
6123
|
}
|
|
6116
|
-
function
|
|
6124
|
+
function Hc(e, t) {
|
|
6117
6125
|
if (t.size === 0) return /* @__PURE__ */ new Map();
|
|
6118
|
-
let n = [...t].sort((e, t) => e - t), r =
|
|
6126
|
+
let n = [...t].sort((e, t) => e - t), r = rc(e.db).select({
|
|
6119
6127
|
id: U.id,
|
|
6120
6128
|
project: U.project
|
|
6121
6129
|
}).from(U).where(j(U.id, n)).all();
|
|
6122
6130
|
return new Map(r.map((e) => [e.id, e.project]));
|
|
6123
6131
|
}
|
|
6124
|
-
function
|
|
6125
|
-
let o = a?.includePackContext ?? !1, s = (t ?? "").trim(), { ordered: c, invalid: l } =
|
|
6132
|
+
function Uc(e, t, n, r = 10, i, a) {
|
|
6133
|
+
let o = a?.includePackContext ?? !1, s = (t ?? "").trim(), { ordered: c, invalid: l } = zc(n ?? []), u = [];
|
|
6126
6134
|
if (l.length > 0 && u.push({
|
|
6127
6135
|
code: "INVALID_ARGUMENT",
|
|
6128
6136
|
field: "ids",
|
|
@@ -6145,10 +6153,10 @@ function Vc(e, t, n, r = 10, i, a) {
|
|
|
6145
6153
|
}
|
|
6146
6154
|
};
|
|
6147
6155
|
let d = [];
|
|
6148
|
-
s && (d =
|
|
6156
|
+
s && (d = Fc(e, s, Math.max(1, Math.trunc(r)), i ?? void 0));
|
|
6149
6157
|
let f = /* @__PURE__ */ new Map();
|
|
6150
6158
|
for (let e = 0; e < d.length; e++) f.set(d[e].id, e + 1);
|
|
6151
|
-
let { items: p, missingNotFound: m, missingProjectMismatch: h, missingFilterMismatch: g } =
|
|
6159
|
+
let { items: p, missingNotFound: m, missingProjectMismatch: h, missingFilterMismatch: g } = Vc(e, c, i ?? {}), _ = new Map(p.map((e) => [e.id, e])), v = new Set(c), y = /* @__PURE__ */ new Set(), b = [];
|
|
6152
6160
|
for (let e of d) {
|
|
6153
6161
|
y.add(e.id);
|
|
6154
6162
|
let t = v.has(e.id) ? "query+id_lookup" : "query";
|
|
@@ -6167,7 +6175,7 @@ function Vc(e, t, n, r = 10, i, a) {
|
|
|
6167
6175
|
rank: null
|
|
6168
6176
|
}), y.add(e));
|
|
6169
6177
|
}
|
|
6170
|
-
let x = s ? (s.match(/[A-Za-z0-9_]+/g) ?? []).map((e) => e.toLowerCase()) : [], S =
|
|
6178
|
+
let x = s ? (s.match(/[A-Za-z0-9_]+/g) ?? []).map((e) => e.toLowerCase()) : [], S = Hc(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 }) => Bc(e, t, n, x, i?.project ?? null, S.get(e.session_id) ?? null, o, C)), T = c.filter((e) => !y.has(e));
|
|
6171
6179
|
return m.length > 0 && u.push({
|
|
6172
6180
|
code: "NOT_FOUND",
|
|
6173
6181
|
field: "ids",
|
|
@@ -6198,7 +6206,7 @@ function Vc(e, t, n, r = 10, i, a) {
|
|
|
6198
6206
|
}
|
|
6199
6207
|
//#endregion
|
|
6200
6208
|
//#region src/pack.ts
|
|
6201
|
-
var
|
|
6209
|
+
var Wc = {
|
|
6202
6210
|
decision: 0,
|
|
6203
6211
|
feature: 1,
|
|
6204
6212
|
bugfix: 2,
|
|
@@ -6207,11 +6215,11 @@ var Hc = {
|
|
|
6207
6215
|
discovery: 5,
|
|
6208
6216
|
exploration: 6,
|
|
6209
6217
|
note: 7
|
|
6210
|
-
},
|
|
6211
|
-
function
|
|
6218
|
+
}, Gc = 365, Kc = "todo todos task tasks pending follow up follow-up next resume continue backlog pick up pick-up", qc = "session summary recap remember last time previous work";
|
|
6219
|
+
function Jc(e) {
|
|
6212
6220
|
return Math.ceil(e.length / 4);
|
|
6213
6221
|
}
|
|
6214
|
-
function
|
|
6222
|
+
function Yc(e) {
|
|
6215
6223
|
let t = [
|
|
6216
6224
|
`[${e.id}]`,
|
|
6217
6225
|
`(${e.kind})`,
|
|
@@ -6219,11 +6227,11 @@ function qc(e) {
|
|
|
6219
6227
|
];
|
|
6220
6228
|
return e.body_text && t.push("-", e.body_text), t.join(" ");
|
|
6221
6229
|
}
|
|
6222
|
-
function
|
|
6230
|
+
function Xc(e, t) {
|
|
6223
6231
|
let n = `## ${e}`;
|
|
6224
|
-
return t.length === 0 ? `${n}\n` : [n, ...t.map(
|
|
6232
|
+
return t.length === 0 ? `${n}\n` : [n, ...t.map(Yc)].join("\n");
|
|
6225
6233
|
}
|
|
6226
|
-
function
|
|
6234
|
+
function Zc(e, t) {
|
|
6227
6235
|
let n = t?.duplicateIds.get(e.id), r = {
|
|
6228
6236
|
id: e.id,
|
|
6229
6237
|
kind: e.kind,
|
|
@@ -6235,18 +6243,18 @@ function Yc(e, t) {
|
|
|
6235
6243
|
};
|
|
6236
6244
|
return n && n.size > 0 && (r.support_count = 1 + n.size, r.duplicate_ids = [...n].sort((e, t) => e - t)), r;
|
|
6237
6245
|
}
|
|
6238
|
-
function
|
|
6246
|
+
function Qc(e) {
|
|
6239
6247
|
return e.trim().toLowerCase().split(/\s+/).join(" ");
|
|
6240
6248
|
}
|
|
6241
|
-
function
|
|
6249
|
+
function $c(e) {
|
|
6242
6250
|
if (e.kind === "session_summary") return null;
|
|
6243
|
-
let t =
|
|
6251
|
+
let t = Qc(e.title), n = Qc(e.body_text);
|
|
6244
6252
|
return !t && !n ? null : `${e.kind.length}:${e.kind}|${t.length}:${t}|${n.length}:${n}`;
|
|
6245
6253
|
}
|
|
6246
|
-
function
|
|
6254
|
+
function el(e, t) {
|
|
6247
6255
|
let n = [];
|
|
6248
6256
|
for (let r of e) {
|
|
6249
|
-
let e =
|
|
6257
|
+
let e = $c(r);
|
|
6250
6258
|
if (e === null) {
|
|
6251
6259
|
n.push(r);
|
|
6252
6260
|
continue;
|
|
@@ -6265,19 +6273,19 @@ function Qc(e, t) {
|
|
|
6265
6273
|
}
|
|
6266
6274
|
return n;
|
|
6267
6275
|
}
|
|
6268
|
-
function
|
|
6276
|
+
function tl(e, t) {
|
|
6269
6277
|
let n = new Set((t.toLowerCase().match(/[a-z0-9_]+/g) ?? []).filter(Boolean));
|
|
6270
6278
|
return n.size === 0 ? e : [...e].sort((e, t) => {
|
|
6271
|
-
let r =
|
|
6279
|
+
let r = nl(e.tags_text, n), i = nl(t.tags_text, n);
|
|
6272
6280
|
return i === r ? (t.created_at ?? "").localeCompare(e.created_at ?? "") : i - r;
|
|
6273
6281
|
});
|
|
6274
6282
|
}
|
|
6275
|
-
function
|
|
6283
|
+
function nl(e, t) {
|
|
6276
6284
|
let n = new Set(e.split(/\s+/).filter(Boolean)), r = 0;
|
|
6277
6285
|
for (let e of t) n.has(e) && r++;
|
|
6278
6286
|
return r;
|
|
6279
6287
|
}
|
|
6280
|
-
function
|
|
6288
|
+
function rl(e) {
|
|
6281
6289
|
let t = e.toLowerCase();
|
|
6282
6290
|
for (let e of [
|
|
6283
6291
|
"todo",
|
|
@@ -6304,7 +6312,7 @@ function tl(e) {
|
|
|
6304
6312
|
]) if (t.includes(e)) return !0;
|
|
6305
6313
|
return !1;
|
|
6306
6314
|
}
|
|
6307
|
-
function
|
|
6315
|
+
function il(e) {
|
|
6308
6316
|
let t = e.toLowerCase();
|
|
6309
6317
|
for (let e of [
|
|
6310
6318
|
"remember",
|
|
@@ -6328,7 +6336,7 @@ function nl(e) {
|
|
|
6328
6336
|
]) if (t.includes(e)) return !0;
|
|
6329
6337
|
return !1;
|
|
6330
6338
|
}
|
|
6331
|
-
function
|
|
6339
|
+
function al(e) {
|
|
6332
6340
|
return {
|
|
6333
6341
|
id: e.id,
|
|
6334
6342
|
kind: e.kind,
|
|
@@ -6343,57 +6351,57 @@ function rl(e) {
|
|
|
6343
6351
|
metadata: e.metadata_json
|
|
6344
6352
|
};
|
|
6345
6353
|
}
|
|
6346
|
-
function
|
|
6354
|
+
function ol(e) {
|
|
6347
6355
|
let t = Date.parse(e);
|
|
6348
6356
|
return Number.isNaN(t) ? -Infinity : t;
|
|
6349
6357
|
}
|
|
6350
|
-
function
|
|
6358
|
+
function sl(e, t) {
|
|
6351
6359
|
let n = Date.now() - t * 864e5;
|
|
6352
|
-
return e.filter((e) =>
|
|
6360
|
+
return e.filter((e) => ol(e.created_at) >= n);
|
|
6353
6361
|
}
|
|
6354
|
-
function
|
|
6362
|
+
function cl(e, t) {
|
|
6355
6363
|
let n = [...e].sort((e, t) => (t.created_at ?? "").localeCompare(e.created_at ?? ""));
|
|
6356
6364
|
return n.sort((e, t) => {
|
|
6357
6365
|
let n = (e) => e === "note" ? 0 : e === "decision" ? 1 : e === "observation" ? 2 : 3;
|
|
6358
6366
|
return n(e.kind) - n(t.kind);
|
|
6359
6367
|
}), n.slice(0, t);
|
|
6360
6368
|
}
|
|
6361
|
-
function
|
|
6369
|
+
function ll(e, t) {
|
|
6362
6370
|
let n = [...e].sort((e, t) => (t.created_at ?? "").localeCompare(e.created_at ?? ""));
|
|
6363
6371
|
return n.sort((e, t) => {
|
|
6364
6372
|
let n = (e) => e === "session_summary" ? 0 : e === "decision" ? 1 : e === "note" ? 2 : e === "observation" ? 3 : e === "entities" ? 4 : 5;
|
|
6365
6373
|
return n(e.kind) - n(t.kind);
|
|
6366
6374
|
}), n.slice(0, t);
|
|
6367
6375
|
}
|
|
6368
|
-
function
|
|
6376
|
+
function ul(e, t, n) {
|
|
6369
6377
|
let r = Math.max(t * 3, t);
|
|
6370
|
-
return
|
|
6378
|
+
return cl(e.recent(r, n ?? null).map(al), t);
|
|
6371
6379
|
}
|
|
6372
|
-
function
|
|
6380
|
+
function dl(e, t, n) {
|
|
6373
6381
|
let r = {
|
|
6374
6382
|
...n ?? {},
|
|
6375
6383
|
kind: "session_summary"
|
|
6376
|
-
}, i = e.recent(t, r).map(
|
|
6384
|
+
}, i = e.recent(t, r).map(al);
|
|
6377
6385
|
if (i.length >= t) return i.slice(0, t);
|
|
6378
|
-
let a = Math.max(t * 3, t), o = e.recent(a, n ?? null).map(
|
|
6386
|
+
let a = Math.max(t * 3, t), o = e.recent(a, n ?? null).map(al), s = new Set(i.map((e) => e.id)), c = cl(o.filter((e) => !s.has(e.id)), t - i.length);
|
|
6379
6387
|
return [...i, ...c];
|
|
6380
6388
|
}
|
|
6381
|
-
function
|
|
6389
|
+
function fl(e) {
|
|
6382
6390
|
if (e == null || typeof e == "boolean") return null;
|
|
6383
6391
|
let t = Number(e);
|
|
6384
6392
|
if (!Number.isFinite(t)) return null;
|
|
6385
6393
|
let n = Math.trunc(t);
|
|
6386
6394
|
return n < 0 ? null : n;
|
|
6387
6395
|
}
|
|
6388
|
-
function
|
|
6396
|
+
function pl(e) {
|
|
6389
6397
|
let t = [], n = /* @__PURE__ */ new Set();
|
|
6390
6398
|
for (let r of e) {
|
|
6391
|
-
let e =
|
|
6399
|
+
let e = fl(r);
|
|
6392
6400
|
e == null || e <= 0 || n.has(e) || (n.add(e), t.push(e));
|
|
6393
6401
|
}
|
|
6394
6402
|
return t;
|
|
6395
6403
|
}
|
|
6396
|
-
function
|
|
6404
|
+
function ml(e) {
|
|
6397
6405
|
if (!Array.isArray(e)) return {
|
|
6398
6406
|
ids: [],
|
|
6399
6407
|
valid: !1
|
|
@@ -6403,11 +6411,11 @@ function fl(e) {
|
|
|
6403
6411
|
valid: !1
|
|
6404
6412
|
};
|
|
6405
6413
|
return {
|
|
6406
|
-
ids:
|
|
6414
|
+
ids: pl(e),
|
|
6407
6415
|
valid: !0
|
|
6408
6416
|
};
|
|
6409
6417
|
}
|
|
6410
|
-
function
|
|
6418
|
+
function hl(e) {
|
|
6411
6419
|
if (!e) return {};
|
|
6412
6420
|
if (typeof e == "string") try {
|
|
6413
6421
|
let t = JSON.parse(e);
|
|
@@ -6417,7 +6425,7 @@ function pl(e) {
|
|
|
6417
6425
|
}
|
|
6418
6426
|
return typeof e == "object" && !Array.isArray(e) ? e : {};
|
|
6419
6427
|
}
|
|
6420
|
-
function
|
|
6428
|
+
function gl(e, t) {
|
|
6421
6429
|
let n = t ? Gt(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
|
|
6422
6430
|
FROM usage_events
|
|
6423
6431
|
WHERE event = 'pack'
|
|
@@ -6425,15 +6433,15 @@ function ml(e, t) {
|
|
|
6425
6433
|
ORDER BY created_at DESC
|
|
6426
6434
|
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();
|
|
6427
6435
|
for (let e of i) {
|
|
6428
|
-
let r =
|
|
6436
|
+
let r = hl(e.metadata_json);
|
|
6429
6437
|
if (t != null) {
|
|
6430
6438
|
let e = typeof r.project == "string" ? r.project : null;
|
|
6431
6439
|
if (e !== t && e !== n) continue;
|
|
6432
6440
|
}
|
|
6433
6441
|
if (!("pack_item_ids" in r)) continue;
|
|
6434
|
-
let { ids: i, valid: a } =
|
|
6442
|
+
let { ids: i, valid: a } = ml(r.pack_item_ids);
|
|
6435
6443
|
if (!a) continue;
|
|
6436
|
-
let o =
|
|
6444
|
+
let o = fl(r.pack_tokens) ?? fl(e.tokens_read);
|
|
6437
6445
|
if (o != null) return {
|
|
6438
6446
|
previousPackIds: i,
|
|
6439
6447
|
previousPackTokens: o
|
|
@@ -6444,20 +6452,20 @@ function ml(e, t) {
|
|
|
6444
6452
|
previousPackTokens: null
|
|
6445
6453
|
};
|
|
6446
6454
|
}
|
|
6447
|
-
function
|
|
6455
|
+
function _l(e, t) {
|
|
6448
6456
|
if (!t) return null;
|
|
6449
6457
|
let n = Gt(t);
|
|
6450
6458
|
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;
|
|
6451
6459
|
}
|
|
6452
|
-
function
|
|
6453
|
-
return
|
|
6460
|
+
function vl(e) {
|
|
6461
|
+
return fl(hl(e.metadata).discovery_tokens) ?? Math.max(2e3, Jc(`${e.title} ${e.body_text}`.trim()));
|
|
6454
6462
|
}
|
|
6455
|
-
function
|
|
6456
|
-
let t =
|
|
6463
|
+
function yl(e) {
|
|
6464
|
+
let t = hl(e.metadata).discovery_group;
|
|
6457
6465
|
return typeof t == "string" && t.trim().length > 0 ? t.trim() : `memory:${e.id}`;
|
|
6458
6466
|
}
|
|
6459
|
-
function
|
|
6460
|
-
let t =
|
|
6467
|
+
function bl(e) {
|
|
6468
|
+
let t = hl(e.metadata), n = fl(t.discovery_tokens);
|
|
6461
6469
|
return n != null && n > 0 ? {
|
|
6462
6470
|
tokens: n,
|
|
6463
6471
|
source: typeof t.discovery_source == "string" && t.discovery_source ? t.discovery_source : "known"
|
|
@@ -6466,16 +6474,16 @@ function vl(e) {
|
|
|
6466
6474
|
source: "unknown"
|
|
6467
6475
|
};
|
|
6468
6476
|
}
|
|
6469
|
-
function
|
|
6470
|
-
return
|
|
6477
|
+
function xl(e) {
|
|
6478
|
+
return hl(e.metadata).discovery_source === "usage" ? "usage" : "estimate";
|
|
6471
6479
|
}
|
|
6472
|
-
function
|
|
6473
|
-
let n = (/* @__PURE__ */ new Date()).toISOString(), r =
|
|
6480
|
+
function Sl(e, t) {
|
|
6481
|
+
let n = (/* @__PURE__ */ new Date()).toISOString(), r = fl(t.pack_tokens) ?? 0, i = fl(t.tokens_saved) ?? 0, a = _l(e, typeof t.project == "string" ? t.project : null);
|
|
6474
6482
|
try {
|
|
6475
6483
|
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));
|
|
6476
6484
|
} catch {}
|
|
6477
6485
|
}
|
|
6478
|
-
function
|
|
6486
|
+
function Cl(e, t, n, r, i) {
|
|
6479
6487
|
let a = /* @__PURE__ */ new Map();
|
|
6480
6488
|
for (let e of t) {
|
|
6481
6489
|
let t = a.get(e.id);
|
|
@@ -6488,46 +6496,46 @@ function xl(e, t, n, r, i) {
|
|
|
6488
6496
|
(!t || e.score > t.score) && a.set(e.id, e);
|
|
6489
6497
|
}
|
|
6490
6498
|
return {
|
|
6491
|
-
merged:
|
|
6499
|
+
merged: Pc(e, [...a.values()], r, i),
|
|
6492
6500
|
ftsCount: t.length,
|
|
6493
6501
|
semanticCount: o
|
|
6494
6502
|
};
|
|
6495
6503
|
}
|
|
6496
|
-
function
|
|
6497
|
-
let o = Math.max(1, Math.trunc(n)), s = !1, c = 0, l = 0, u, d =
|
|
6504
|
+
function wl(e, t, n = 10, r = null, i, a) {
|
|
6505
|
+
let o = Math.max(1, Math.trunc(n)), s = !1, c = 0, l = 0, u, d = rl(t), f = !d && il(t);
|
|
6498
6506
|
if (d) {
|
|
6499
|
-
let n =
|
|
6507
|
+
let n = Fc(e, `${t} ${Kc}`.trim(), o, i);
|
|
6500
6508
|
if (c = n.length, a && a.length > 0) {
|
|
6501
|
-
let t =
|
|
6509
|
+
let t = Cl(e, n, a, o, i);
|
|
6502
6510
|
n = t.merged, l = t.semanticCount;
|
|
6503
6511
|
}
|
|
6504
|
-
if (n.length === 0) s = !0, u =
|
|
6512
|
+
if (n.length === 0) s = !0, u = ul(e, o, i);
|
|
6505
6513
|
else {
|
|
6506
|
-
let e =
|
|
6507
|
-
u =
|
|
6514
|
+
let e = sl(n, Gc);
|
|
6515
|
+
u = cl(e.length > 0 ? e : n, o);
|
|
6508
6516
|
}
|
|
6509
6517
|
} else if (f) {
|
|
6510
|
-
let n =
|
|
6511
|
-
if (c = n.length, n.length === 0 && (n =
|
|
6518
|
+
let n = Fc(e, t.trim().length > 0 ? t : qc, o, i);
|
|
6519
|
+
if (c = n.length, n.length === 0 && (n = Fc(e, qc, o, {
|
|
6512
6520
|
...i ?? {},
|
|
6513
6521
|
kind: "session_summary"
|
|
6514
6522
|
}), c = n.length), a && a.length > 0) {
|
|
6515
|
-
let t =
|
|
6523
|
+
let t = Cl(e, n, a, o, i);
|
|
6516
6524
|
n = t.merged, l = t.semanticCount;
|
|
6517
6525
|
}
|
|
6518
|
-
u =
|
|
6526
|
+
u = ll(n, o), u.length === 0 && (s = !0, u = dl(e, o, i));
|
|
6519
6527
|
let r = u[0]?.id;
|
|
6520
6528
|
if (r != null) {
|
|
6521
|
-
let t = Math.max(0, Math.floor(o / 2)), n =
|
|
6522
|
-
n.length > 0 && (u = n.map(
|
|
6529
|
+
let t = Math.max(0, Math.floor(o / 2)), n = Lc(e, void 0, r, t, Math.max(0, o - t - 1), i ?? null);
|
|
6530
|
+
n.length > 0 && (u = n.map(al));
|
|
6523
6531
|
}
|
|
6524
6532
|
} else {
|
|
6525
|
-
let n =
|
|
6533
|
+
let n = Fc(e, t, o, i);
|
|
6526
6534
|
if (a && a.length > 0) {
|
|
6527
|
-
let t =
|
|
6535
|
+
let t = Cl(e, n, a, o, i);
|
|
6528
6536
|
u = t.merged, c = t.ftsCount, l = t.semanticCount;
|
|
6529
6537
|
} else u = n, c = u.length;
|
|
6530
|
-
u.length === 0 && (s = !0, u = e.recent(o, i ?? null).map(
|
|
6538
|
+
u.length === 0 && (s = !0, u = e.recent(o, i ?? null).map(al));
|
|
6531
6539
|
}
|
|
6532
6540
|
let p = u.filter((e) => e.kind === "session_summary").slice(0, 1);
|
|
6533
6541
|
if (p.length === 0) {
|
|
@@ -6552,7 +6560,7 @@ function Sl(e, t, n = 10, r = null, i, a) {
|
|
|
6552
6560
|
}];
|
|
6553
6561
|
}
|
|
6554
6562
|
}
|
|
6555
|
-
let m = u.filter((e) => e.kind !== "session_summary").slice(0, 3), h = new Set(m.map((e) => e.id)), g = Object.keys(
|
|
6563
|
+
let m = u.filter((e) => e.kind !== "session_summary").slice(0, 3), h = new Set(m.map((e) => e.id)), g = Object.keys(Wc), _ = [...u].filter((e) => e.kind !== "session_summary" && !h.has(e.id)).sort((e, t) => (Wc[e.kind] ?? 99) - (Wc[t.kind] ?? 99));
|
|
6556
6564
|
f && _.length === 0 && (_ = u.filter((e) => e.kind !== "session_summary")), _.length === 0 && (_ = e.recentByKinds(g, Math.max(o * 3, 10), i ?? null).map((e) => ({
|
|
6557
6565
|
id: e.id,
|
|
6558
6566
|
kind: e.kind,
|
|
@@ -6565,55 +6573,55 @@ function Sl(e, t, n = 10, r = null, i, a) {
|
|
|
6565
6573
|
score: 0,
|
|
6566
6574
|
session_id: e.session_id,
|
|
6567
6575
|
metadata: e.metadata_json
|
|
6568
|
-
}))), _.length === 0 && (_ = [...m]), _ =
|
|
6576
|
+
}))), _.length === 0 && (_ = [...m]), _ = tl(_, t);
|
|
6569
6577
|
let v = {
|
|
6570
6578
|
canonicalByKey: /* @__PURE__ */ new Map(),
|
|
6571
6579
|
duplicateIds: /* @__PURE__ */ new Map()
|
|
6572
6580
|
};
|
|
6573
|
-
p =
|
|
6581
|
+
p = el(p, v), m = el(m, v), _ = el(_, v);
|
|
6574
6582
|
let y = p, b = m, x = _;
|
|
6575
6583
|
if (r != null && r > 0) {
|
|
6576
6584
|
let e = 0;
|
|
6577
6585
|
y = [];
|
|
6578
6586
|
for (let t of p) {
|
|
6579
|
-
let n =
|
|
6587
|
+
let n = Jc(Yc(t));
|
|
6580
6588
|
if (e + n > r) break;
|
|
6581
6589
|
e += n, y.push(t);
|
|
6582
6590
|
}
|
|
6583
6591
|
b = [];
|
|
6584
6592
|
for (let t of m) {
|
|
6585
|
-
let n =
|
|
6593
|
+
let n = Jc(Yc(t));
|
|
6586
6594
|
if (e + n > r) break;
|
|
6587
6595
|
e += n, b.push(t);
|
|
6588
6596
|
}
|
|
6589
6597
|
x = [];
|
|
6590
6598
|
for (let t of _) {
|
|
6591
|
-
let n =
|
|
6599
|
+
let n = Jc(Yc(t));
|
|
6592
6600
|
if (e + n > r) break;
|
|
6593
6601
|
e += n, x.push(t);
|
|
6594
6602
|
}
|
|
6595
6603
|
}
|
|
6596
6604
|
let S = [
|
|
6597
|
-
|
|
6598
|
-
|
|
6599
|
-
|
|
6600
|
-
].join("\n\n"), C =
|
|
6605
|
+
Xc("Summary", y),
|
|
6606
|
+
Xc("Timeline", b),
|
|
6607
|
+
Xc("Observations", x)
|
|
6608
|
+
].join("\n\n"), C = Jc(S), w = /* @__PURE__ */ new Set(), T = [], E = [], ee = [];
|
|
6601
6609
|
for (let e of [
|
|
6602
6610
|
...y,
|
|
6603
6611
|
...b,
|
|
6604
6612
|
...x
|
|
6605
|
-
]) w.has(e.id) || (w.add(e.id), E.push(e), T.push(
|
|
6606
|
-
let { previousPackIds: te, previousPackTokens: D } =
|
|
6613
|
+
]) w.has(e.id) || (w.add(e.id), E.push(e), T.push(Zc(e, v)), ee.push(e.id));
|
|
6614
|
+
let { previousPackIds: te, previousPackTokens: D } = gl(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 + vl(t), 0), oe = /* @__PURE__ */ new Map();
|
|
6607
6615
|
for (let e of E) {
|
|
6608
|
-
let t =
|
|
6616
|
+
let t = yl(e), n = vl(e);
|
|
6609
6617
|
n > (oe.get(t) ?? 0) && oe.set(t, n);
|
|
6610
6618
|
}
|
|
6611
6619
|
let se = [...oe.values()].reduce((e, t) => e + t, 0), ce = Math.max(0, se - C), M = 0, N = 0, P = 0, F = {};
|
|
6612
6620
|
for (let e of E) {
|
|
6613
|
-
let t =
|
|
6621
|
+
let t = bl(e);
|
|
6614
6622
|
t.tokens > 0 ? (M += t.tokens, N += 1, F[t.source] = (F[t.source] ?? 0) + 1) : P += 1;
|
|
6615
6623
|
}
|
|
6616
|
-
let le = Math.max(0, M - C), ue = M > 0 ? M / Math.max(C, 1) : null, I = E.map(
|
|
6624
|
+
let le = Math.max(0, M - C), ue = M > 0 ? M / Math.max(C, 1) : null, I = E.map(xl), 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 = {
|
|
6617
6625
|
total_items: T.length,
|
|
6618
6626
|
pack_tokens: C,
|
|
6619
6627
|
fallback_used: s,
|
|
@@ -6649,7 +6657,7 @@ function Sl(e, t, n = 10, r = null, i, a) {
|
|
|
6649
6657
|
fuzzy: 0
|
|
6650
6658
|
}
|
|
6651
6659
|
};
|
|
6652
|
-
return
|
|
6660
|
+
return Sl(e, _e), {
|
|
6653
6661
|
context: t,
|
|
6654
6662
|
items: T,
|
|
6655
6663
|
item_ids: ee,
|
|
@@ -6657,7 +6665,7 @@ function Sl(e, t, n = 10, r = null, i, a) {
|
|
|
6657
6665
|
metrics: _e
|
|
6658
6666
|
};
|
|
6659
6667
|
}
|
|
6660
|
-
async function
|
|
6668
|
+
async function Tl(e, t, n = 10, r = null, i) {
|
|
6661
6669
|
let a = [];
|
|
6662
6670
|
try {
|
|
6663
6671
|
a = (await Ho(e.db, t, n, { project: i?.project })).map((e) => {
|
|
@@ -6681,24 +6689,24 @@ async function Cl(e, t, n = 10, r = null, i) {
|
|
|
6681
6689
|
};
|
|
6682
6690
|
});
|
|
6683
6691
|
} catch {}
|
|
6684
|
-
return
|
|
6692
|
+
return wl(e, t, n, r, i, a);
|
|
6685
6693
|
}
|
|
6686
6694
|
//#endregion
|
|
6687
6695
|
//#region src/raw-event-flush.ts
|
|
6688
|
-
var
|
|
6689
|
-
function
|
|
6696
|
+
var El = "raw_events_v1";
|
|
6697
|
+
function Dl(e, t = 280) {
|
|
6690
6698
|
let n = e.replace(/\s+/g, " ").trim();
|
|
6691
6699
|
return n.length <= t ? n : `${n.slice(0, t - 3).trimEnd()}...`;
|
|
6692
6700
|
}
|
|
6693
|
-
function
|
|
6701
|
+
function Ol(e) {
|
|
6694
6702
|
let t = (e ?? "").trim().toLowerCase();
|
|
6695
6703
|
return t === "openai" ? "OpenAI" : t === "anthropic" ? "Anthropic" : t ? t.charAt(0).toUpperCase() + t.slice(1) : "Observer";
|
|
6696
6704
|
}
|
|
6697
|
-
function
|
|
6698
|
-
let n =
|
|
6705
|
+
function kl(e, t) {
|
|
6706
|
+
let n = Ol(t), r = String(e.message ?? "").trim().toLowerCase();
|
|
6699
6707
|
return e instanceof Is ? `${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.`;
|
|
6700
6708
|
}
|
|
6701
|
-
function
|
|
6709
|
+
function Al(e) {
|
|
6702
6710
|
let t = 0, n = 0;
|
|
6703
6711
|
for (let r of e) r.type === "user_prompt" && t++, r.type === "tool.execute.after" && n++;
|
|
6704
6712
|
let r = [];
|
|
@@ -6743,7 +6751,7 @@ function Ol(e) {
|
|
|
6743
6751
|
filesRead: [...o].sort()
|
|
6744
6752
|
};
|
|
6745
6753
|
}
|
|
6746
|
-
async function
|
|
6754
|
+
async function jl(e, t, n) {
|
|
6747
6755
|
let { source: r = "opencode", cwd: i, project: a, startedAt: o } = n, { opencodeSessionId: s, maxEvents: c } = n, l = n.allowEmptyFlush ?? !1;
|
|
6748
6756
|
r = (r ?? "").trim().toLowerCase() || "opencode";
|
|
6749
6757
|
let u = e.rawEventSessionMeta(s, r);
|
|
@@ -6773,7 +6781,7 @@ async function kl(e, t, n) {
|
|
|
6773
6781
|
flushed: 0,
|
|
6774
6782
|
updatedState: 0
|
|
6775
6783
|
};
|
|
6776
|
-
let { batchId: g, status: _ } = e.getOrCreateRawEventFlushBatch(s, r, m, h,
|
|
6784
|
+
let { batchId: g, status: _ } = e.getOrCreateRawEventFlushBatch(s, r, m, h, El);
|
|
6777
6785
|
if (_ === "completed") return e.updateRawEventFlushState(s, h, r), {
|
|
6778
6786
|
flushed: 0,
|
|
6779
6787
|
updatedState: 1
|
|
@@ -6782,7 +6790,7 @@ async function kl(e, t, n) {
|
|
|
6782
6790
|
flushed: 0,
|
|
6783
6791
|
updatedState: 0
|
|
6784
6792
|
};
|
|
6785
|
-
let v =
|
|
6793
|
+
let v = Al(f);
|
|
6786
6794
|
v.opencodeSessionId = s, v.source = r, v.streamId = s, v.flusher = "raw_events", v.flushBatch = {
|
|
6787
6795
|
batch_id: g,
|
|
6788
6796
|
start_event_seq: m,
|
|
@@ -6803,7 +6811,7 @@ async function kl(e, t, n) {
|
|
|
6803
6811
|
flushed: f.length,
|
|
6804
6812
|
updatedState: 1
|
|
6805
6813
|
};
|
|
6806
|
-
let a = t.observer?.getStatus?.()?.provider, o =
|
|
6814
|
+
let a = t.observer?.getStatus?.()?.provider, o = Dl(kl(i, a));
|
|
6807
6815
|
throw e.recordRawEventFlushBatchFailure(g, {
|
|
6808
6816
|
message: o,
|
|
6809
6817
|
errorType: i instanceof Is ? "ObserverAuthError" : i.name,
|
|
@@ -6819,18 +6827,18 @@ async function kl(e, t, n) {
|
|
|
6819
6827
|
}
|
|
6820
6828
|
//#endregion
|
|
6821
6829
|
//#region src/raw-event-sweeper.ts
|
|
6822
|
-
var
|
|
6823
|
-
function
|
|
6830
|
+
var Ml = 60;
|
|
6831
|
+
function Nl(e, t) {
|
|
6824
6832
|
let n = process.env[e];
|
|
6825
6833
|
if (n == null) return t;
|
|
6826
6834
|
let r = Number.parseInt(n, 10);
|
|
6827
6835
|
return Number.isFinite(r) ? r : t;
|
|
6828
6836
|
}
|
|
6829
|
-
function
|
|
6837
|
+
function Pl(e) {
|
|
6830
6838
|
let t = (process.env[e] ?? "1").trim().toLowerCase();
|
|
6831
6839
|
return t === "0" || t === "false" || t === "off";
|
|
6832
6840
|
}
|
|
6833
|
-
var
|
|
6841
|
+
var Fl = class {
|
|
6834
6842
|
store;
|
|
6835
6843
|
ingestOpts;
|
|
6836
6844
|
active = !1;
|
|
@@ -6848,7 +6856,7 @@ var Nl = class {
|
|
|
6848
6856
|
this.store = e, this.ingestOpts = t;
|
|
6849
6857
|
}
|
|
6850
6858
|
enabled() {
|
|
6851
|
-
return !
|
|
6859
|
+
return !Pl("CODEMEM_RAW_EVENTS_SWEEPER");
|
|
6852
6860
|
}
|
|
6853
6861
|
intervalMs() {
|
|
6854
6862
|
let e = process.env.CODEMEM_RAW_EVENTS_SWEEPER_INTERVAL_MS;
|
|
@@ -6860,31 +6868,31 @@ var Nl = class {
|
|
|
6860
6868
|
return Number.isFinite(n) && n > 0 ? Math.max(1e3, n * 1e3) : 3e4;
|
|
6861
6869
|
}
|
|
6862
6870
|
idleMs() {
|
|
6863
|
-
return
|
|
6871
|
+
return Nl("CODEMEM_RAW_EVENTS_SWEEPER_IDLE_MS", 12e4);
|
|
6864
6872
|
}
|
|
6865
6873
|
limit() {
|
|
6866
|
-
return
|
|
6874
|
+
return Nl("CODEMEM_RAW_EVENTS_SWEEPER_LIMIT", 25);
|
|
6867
6875
|
}
|
|
6868
6876
|
workerMaxEvents() {
|
|
6869
|
-
let e =
|
|
6877
|
+
let e = Nl("CODEMEM_RAW_EVENTS_WORKER_MAX_EVENTS", 250);
|
|
6870
6878
|
return e <= 0 ? null : e;
|
|
6871
6879
|
}
|
|
6872
6880
|
retentionMs() {
|
|
6873
|
-
return
|
|
6881
|
+
return Nl("CODEMEM_RAW_EVENTS_RETENTION_MS", 0);
|
|
6874
6882
|
}
|
|
6875
6883
|
autoFlushEnabled() {
|
|
6876
6884
|
return (process.env.CODEMEM_RAW_EVENTS_AUTO_FLUSH ?? "").trim() === "1";
|
|
6877
6885
|
}
|
|
6878
6886
|
debounceMs() {
|
|
6879
|
-
return
|
|
6887
|
+
return Nl("CODEMEM_RAW_EVENTS_DEBOUNCE_MS", 6e4);
|
|
6880
6888
|
}
|
|
6881
6889
|
stuckBatchMs() {
|
|
6882
|
-
return
|
|
6890
|
+
return Nl("CODEMEM_RAW_EVENTS_STUCK_BATCH_MS", 3e5);
|
|
6883
6891
|
}
|
|
6884
6892
|
handleAuthError(e) {
|
|
6885
|
-
if (this.authBackoffUntil = Date.now() / 1e3 +
|
|
6893
|
+
if (this.authBackoffUntil = Date.now() / 1e3 + Ml, !this.authErrorLogged) {
|
|
6886
6894
|
this.authErrorLogged = !0;
|
|
6887
|
-
let t = `codemem: observer auth error — backing off for ${
|
|
6895
|
+
let t = `codemem: observer auth error — backing off for ${Ml}s. Refresh your provider credentials or update observer_provider in settings. (${e.message})`;
|
|
6888
6896
|
console.error(t);
|
|
6889
6897
|
}
|
|
6890
6898
|
}
|
|
@@ -6964,7 +6972,7 @@ var Nl = class {
|
|
|
6964
6972
|
let r = this.autoFlushTimers.get(n);
|
|
6965
6973
|
r && (clearTimeout(r), this.autoFlushTimers.delete(n));
|
|
6966
6974
|
try {
|
|
6967
|
-
await
|
|
6975
|
+
await jl(this.store, this.ingestOpts, {
|
|
6968
6976
|
opencodeSessionId: e,
|
|
6969
6977
|
source: t,
|
|
6970
6978
|
cwd: null,
|
|
@@ -7022,7 +7030,7 @@ var Nl = class {
|
|
|
7022
7030
|
if (!this.sessionFlushing.has(r)) {
|
|
7023
7031
|
this.sessionFlushing.add(r);
|
|
7024
7032
|
try {
|
|
7025
|
-
await
|
|
7033
|
+
await jl(this.store, this.ingestOpts, {
|
|
7026
7034
|
opencodeSessionId: n,
|
|
7027
7035
|
source: t,
|
|
7028
7036
|
cwd: null,
|
|
@@ -7050,7 +7058,7 @@ var Nl = class {
|
|
|
7050
7058
|
if (!this.sessionFlushing.has(r)) {
|
|
7051
7059
|
this.sessionFlushing.add(r);
|
|
7052
7060
|
try {
|
|
7053
|
-
await
|
|
7061
|
+
await jl(this.store, this.ingestOpts, {
|
|
7054
7062
|
opencodeSessionId: n,
|
|
7055
7063
|
source: t,
|
|
7056
7064
|
cwd: null,
|
|
@@ -7074,7 +7082,7 @@ var Nl = class {
|
|
|
7074
7082
|
};
|
|
7075
7083
|
//#endregion
|
|
7076
7084
|
//#region src/sync-replication.ts
|
|
7077
|
-
function
|
|
7085
|
+
function Il(e) {
|
|
7078
7086
|
if (e == null) return null;
|
|
7079
7087
|
if (typeof e == "number" && Number.isFinite(e)) return e;
|
|
7080
7088
|
if (typeof e == "string" && e.trim().length > 0) {
|
|
@@ -7086,7 +7094,7 @@ function Pl(e) {
|
|
|
7086
7094
|
function Q(e) {
|
|
7087
7095
|
return e == null ? null : String(e);
|
|
7088
7096
|
}
|
|
7089
|
-
function
|
|
7097
|
+
function Ll(e, t) {
|
|
7090
7098
|
if (!e.payload_json) return null;
|
|
7091
7099
|
let n;
|
|
7092
7100
|
try {
|
|
@@ -7096,14 +7104,14 @@ function Fl(e, t) {
|
|
|
7096
7104
|
}
|
|
7097
7105
|
let r = n.metadata_json, i = r && typeof r == "object" && !Array.isArray(r) ? { ...r } : {};
|
|
7098
7106
|
return {
|
|
7099
|
-
session_id:
|
|
7107
|
+
session_id: Il(n.session_id),
|
|
7100
7108
|
kind: Q(n.kind),
|
|
7101
7109
|
title: Q(n.title),
|
|
7102
7110
|
subtitle: Q(n.subtitle),
|
|
7103
7111
|
body_text: Q(n.body_text),
|
|
7104
|
-
confidence:
|
|
7112
|
+
confidence: Il(n.confidence),
|
|
7105
7113
|
tags_text: Q(n.tags_text),
|
|
7106
|
-
active:
|
|
7114
|
+
active: Il(n.active),
|
|
7107
7115
|
created_at: Q(n.created_at),
|
|
7108
7116
|
updated_at: Q(n.updated_at),
|
|
7109
7117
|
metadata_json: i,
|
|
@@ -7120,24 +7128,24 @@ function Fl(e, t) {
|
|
|
7120
7128
|
concepts: n.concepts ?? null,
|
|
7121
7129
|
files_read: n.files_read ?? null,
|
|
7122
7130
|
files_modified: n.files_modified ?? null,
|
|
7123
|
-
user_prompt_id:
|
|
7124
|
-
prompt_number:
|
|
7131
|
+
user_prompt_id: Il(n.user_prompt_id),
|
|
7132
|
+
prompt_number: Il(n.prompt_number),
|
|
7125
7133
|
deleted_at: Q(n.deleted_at),
|
|
7126
|
-
rev:
|
|
7134
|
+
rev: Il(n.rev) ?? 0,
|
|
7127
7135
|
import_key: Q(n.import_key)
|
|
7128
7136
|
};
|
|
7129
7137
|
}
|
|
7130
|
-
function
|
|
7138
|
+
function Rl(e, t) {
|
|
7131
7139
|
return {
|
|
7132
7140
|
...e,
|
|
7133
7141
|
clock_device_id: t
|
|
7134
7142
|
};
|
|
7135
7143
|
}
|
|
7136
|
-
function
|
|
7144
|
+
function zl(e) {
|
|
7137
7145
|
let t = z(e);
|
|
7138
7146
|
return typeof t.clock_device_id == "string" ? t.clock_device_id : "";
|
|
7139
7147
|
}
|
|
7140
|
-
function
|
|
7148
|
+
function Bl(e, t) {
|
|
7141
7149
|
let n = new TextEncoder(), r = [], i = [], a = 9;
|
|
7142
7150
|
for (let o of e) {
|
|
7143
7151
|
let e = n.encode(JSON.stringify(o)).byteLength, s = i.length === 0 ? e : e + 1;
|
|
@@ -7149,14 +7157,14 @@ function Rl(e, t) {
|
|
|
7149
7157
|
}
|
|
7150
7158
|
return i.length > 0 && r.push(i), r;
|
|
7151
7159
|
}
|
|
7152
|
-
function
|
|
7160
|
+
function Vl(e, t) {
|
|
7153
7161
|
let n = N(e, { schema: H }).select({
|
|
7154
7162
|
last_applied_cursor: rn.last_applied_cursor,
|
|
7155
7163
|
last_acked_cursor: rn.last_acked_cursor
|
|
7156
7164
|
}).from(rn).where(k(rn.peer_device_id, t)).get();
|
|
7157
7165
|
return n ? [n.last_applied_cursor, n.last_acked_cursor] : [null, null];
|
|
7158
7166
|
}
|
|
7159
|
-
function
|
|
7167
|
+
function Hl(e, t, n = {}) {
|
|
7160
7168
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = n.lastApplied ?? null, a = n.lastAcked ?? null;
|
|
7161
7169
|
N(e, { schema: H }).insert(rn).values({
|
|
7162
7170
|
peer_device_id: t,
|
|
@@ -7172,7 +7180,7 @@ function Bl(e, t, n = {}) {
|
|
|
7172
7180
|
}
|
|
7173
7181
|
}).run();
|
|
7174
7182
|
}
|
|
7175
|
-
var
|
|
7183
|
+
var Ul = [
|
|
7176
7184
|
"op_id",
|
|
7177
7185
|
"entity_type",
|
|
7178
7186
|
"entity_id",
|
|
@@ -7183,26 +7191,26 @@ var Vl = [
|
|
|
7183
7191
|
"device_id",
|
|
7184
7192
|
"created_at"
|
|
7185
7193
|
];
|
|
7186
|
-
function
|
|
7194
|
+
function Wl(e) {
|
|
7187
7195
|
if (typeof e != "object" || !e) return [];
|
|
7188
7196
|
let t = e.ops;
|
|
7189
7197
|
return Array.isArray(t) ? t.filter((e) => {
|
|
7190
7198
|
if (typeof e != "object" || !e) return !1;
|
|
7191
7199
|
let t = e;
|
|
7192
|
-
return
|
|
7200
|
+
return Ul.every((e) => t[e] !== void 0 && t[e] !== null);
|
|
7193
7201
|
}) : [];
|
|
7194
7202
|
}
|
|
7195
|
-
function
|
|
7203
|
+
function Gl(e, t, n) {
|
|
7196
7204
|
return [
|
|
7197
7205
|
e,
|
|
7198
7206
|
t,
|
|
7199
7207
|
n
|
|
7200
7208
|
];
|
|
7201
7209
|
}
|
|
7202
|
-
function
|
|
7210
|
+
function Kl(e, t) {
|
|
7203
7211
|
return e[0] === t[0] ? e[1] === t[1] ? e[2] > t[2] : e[1] > t[1] : e[0] > t[0];
|
|
7204
7212
|
}
|
|
7205
|
-
function
|
|
7213
|
+
function ql(e, t) {
|
|
7206
7214
|
let n = N(e, { schema: H }), r = a(), i = (/* @__PURE__ */ new Date()).toISOString(), o = n.select().from(W).where(k(W.id, t.memoryId)).get(), s = Number(o?.rev ?? 0), c = o?.updated_at ?? i, l = o?.import_key ?? String(t.memoryId), u = z(o?.metadata_json), d = typeof u.clock_device_id == "string" && u.clock_device_id.trim().length > 0 ? u.clock_device_id : t.deviceId, f;
|
|
7207
7215
|
if (t.payload) f = B(t.payload);
|
|
7208
7216
|
else if (o && t.opType === "upsert") {
|
|
@@ -7257,17 +7265,17 @@ function Gl(e, t) {
|
|
|
7257
7265
|
created_at: i
|
|
7258
7266
|
}).run(), r;
|
|
7259
7267
|
}
|
|
7260
|
-
function
|
|
7268
|
+
function Jl(e) {
|
|
7261
7269
|
let t = e.indexOf("|");
|
|
7262
7270
|
return t < 0 ? null : [e.slice(0, t), e.slice(t + 1)];
|
|
7263
7271
|
}
|
|
7264
|
-
function
|
|
7272
|
+
function Yl(e, t) {
|
|
7265
7273
|
return `${e}|${t}`;
|
|
7266
7274
|
}
|
|
7267
|
-
function
|
|
7275
|
+
function Xl(e, t, n = 100, r) {
|
|
7268
7276
|
let i = N(e, { schema: H }), a = nn, o = [];
|
|
7269
7277
|
if (t) {
|
|
7270
|
-
let e =
|
|
7278
|
+
let e = Jl(t);
|
|
7271
7279
|
if (e) {
|
|
7272
7280
|
let [t, n] = e;
|
|
7273
7281
|
o.push(ce(A(a.created_at, t), D(k(a.created_at, t), A(a.op_id, n))));
|
|
@@ -7288,11 +7296,11 @@ function Jl(e, t, n = 100, r) {
|
|
|
7288
7296
|
})), u = null;
|
|
7289
7297
|
if (c.length > 0) {
|
|
7290
7298
|
let e = c.at(-1);
|
|
7291
|
-
e && (u =
|
|
7299
|
+
e && (u = Yl(e.created_at, e.op_id));
|
|
7292
7300
|
}
|
|
7293
7301
|
return [l, u];
|
|
7294
7302
|
}
|
|
7295
|
-
function
|
|
7303
|
+
function Zl(e) {
|
|
7296
7304
|
if (!Array.isArray(e)) return [];
|
|
7297
7305
|
let t = [];
|
|
7298
7306
|
for (let n of e) {
|
|
@@ -7301,25 +7309,25 @@ function Yl(e) {
|
|
|
7301
7309
|
}
|
|
7302
7310
|
return t;
|
|
7303
7311
|
}
|
|
7304
|
-
function
|
|
7305
|
-
return Array.isArray(e) ?
|
|
7312
|
+
function Ql(e) {
|
|
7313
|
+
return Array.isArray(e) ? Zl(e) : typeof e == "string" ? e.split(",").map((e) => e.trim()).filter(Boolean) : [];
|
|
7306
7314
|
}
|
|
7307
|
-
function
|
|
7315
|
+
function $l(e) {
|
|
7308
7316
|
if (!e) return [];
|
|
7309
7317
|
try {
|
|
7310
|
-
return
|
|
7318
|
+
return Zl(JSON.parse(e));
|
|
7311
7319
|
} catch {
|
|
7312
7320
|
return [];
|
|
7313
7321
|
}
|
|
7314
7322
|
}
|
|
7315
|
-
function
|
|
7323
|
+
function eu(e) {
|
|
7316
7324
|
let t = String(e ?? "").trim().replaceAll("\\", "/");
|
|
7317
7325
|
if (!t) return "";
|
|
7318
7326
|
let n = t.split("/").filter(Boolean);
|
|
7319
7327
|
return n.length > 0 ? n[n.length - 1] ?? "" : "";
|
|
7320
7328
|
}
|
|
7321
|
-
function
|
|
7322
|
-
let n = N(e, { schema: H }), r = tt(), i = process.env.CODEMEM_SYNC_PROJECTS_INCLUDE, a = process.env.CODEMEM_SYNC_PROJECTS_EXCLUDE, o =
|
|
7329
|
+
function tu(e, t) {
|
|
7330
|
+
let n = N(e, { schema: H }), r = tt(), i = process.env.CODEMEM_SYNC_PROJECTS_INCLUDE, a = process.env.CODEMEM_SYNC_PROJECTS_EXCLUDE, o = Ql(i === void 0 ? r.sync_projects_include : i), s = Ql(a === void 0 ? r.sync_projects_exclude : a);
|
|
7323
7331
|
if (!t) return {
|
|
7324
7332
|
include: o,
|
|
7325
7333
|
exclude: s
|
|
@@ -7332,15 +7340,15 @@ function $l(e, t) {
|
|
|
7332
7340
|
include: o,
|
|
7333
7341
|
exclude: s
|
|
7334
7342
|
} : {
|
|
7335
|
-
include:
|
|
7336
|
-
exclude:
|
|
7343
|
+
include: $l(c.projects_include_json),
|
|
7344
|
+
exclude: $l(c.projects_exclude_json)
|
|
7337
7345
|
};
|
|
7338
7346
|
}
|
|
7339
|
-
function
|
|
7340
|
-
let { include: r, exclude: i } =
|
|
7347
|
+
function nu(e, t, n) {
|
|
7348
|
+
let { include: r, exclude: i } = tu(e, n), a = String(t ?? "").trim(), o = eu(a);
|
|
7341
7349
|
return i.some((e) => e === a || e === o) ? !1 : r.length === 0 ? !0 : r.some((e) => e === a || e === o);
|
|
7342
7350
|
}
|
|
7343
|
-
function
|
|
7351
|
+
function ru(e) {
|
|
7344
7352
|
if (!e) return !1;
|
|
7345
7353
|
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();
|
|
7346
7354
|
if (!t && r && (t = r), !t) {
|
|
@@ -7350,10 +7358,10 @@ function tu(e) {
|
|
|
7350
7358
|
}
|
|
7351
7359
|
return t === "shared";
|
|
7352
7360
|
}
|
|
7353
|
-
function
|
|
7361
|
+
function iu(e, t) {
|
|
7354
7362
|
return t ? !!N(e, { schema: H }).select({ claimed_local_actor: J.claimed_local_actor }).from(J).where(k(J.peer_device_id, t)).limit(1).get()?.claimed_local_actor : !1;
|
|
7355
7363
|
}
|
|
7356
|
-
function
|
|
7364
|
+
function au(e) {
|
|
7357
7365
|
if (!e || !e.trim()) return null;
|
|
7358
7366
|
try {
|
|
7359
7367
|
let t = JSON.parse(e);
|
|
@@ -7362,16 +7370,16 @@ function ru(e) {
|
|
|
7362
7370
|
return null;
|
|
7363
7371
|
}
|
|
7364
7372
|
}
|
|
7365
|
-
function
|
|
7373
|
+
function ou(e, t, n) {
|
|
7366
7374
|
let r = [], i = null, a = 0, o = null;
|
|
7367
7375
|
for (let s of t) {
|
|
7368
7376
|
if (s.entity_type === "memory_item") {
|
|
7369
|
-
let t =
|
|
7377
|
+
let t = au(s.payload_json);
|
|
7370
7378
|
if (s.op_type === "delete" && t == null) {
|
|
7371
|
-
r.push(s), i =
|
|
7379
|
+
r.push(s), i = Yl(s.created_at, s.op_id);
|
|
7372
7380
|
continue;
|
|
7373
7381
|
}
|
|
7374
|
-
if (!
|
|
7382
|
+
if (!ru(t) && !iu(e, n)) {
|
|
7375
7383
|
a += 1, o ||= {
|
|
7376
7384
|
reason: "visibility_filter",
|
|
7377
7385
|
op_id: s.op_id,
|
|
@@ -7380,11 +7388,11 @@ function iu(e, t, n) {
|
|
|
7380
7388
|
entity_id: s.entity_id,
|
|
7381
7389
|
visibility: typeof t?.visibility == "string" ? String(t.visibility) : null,
|
|
7382
7390
|
skipped_count: 0
|
|
7383
|
-
}, i =
|
|
7391
|
+
}, i = Yl(s.created_at, s.op_id);
|
|
7384
7392
|
continue;
|
|
7385
7393
|
}
|
|
7386
7394
|
let c = typeof t?.project == "string" && t.project.trim() ? t.project.trim() : null;
|
|
7387
|
-
if (!
|
|
7395
|
+
if (!nu(e, c, n)) {
|
|
7388
7396
|
a += 1, o ||= {
|
|
7389
7397
|
reason: "project_filter",
|
|
7390
7398
|
op_id: s.op_id,
|
|
@@ -7393,11 +7401,11 @@ function iu(e, t, n) {
|
|
|
7393
7401
|
entity_id: s.entity_id,
|
|
7394
7402
|
project: c,
|
|
7395
7403
|
skipped_count: 0
|
|
7396
|
-
}, i =
|
|
7404
|
+
}, i = Yl(s.created_at, s.op_id);
|
|
7397
7405
|
continue;
|
|
7398
7406
|
}
|
|
7399
7407
|
}
|
|
7400
|
-
r.push(s), i =
|
|
7408
|
+
r.push(s), i = Yl(s.created_at, s.op_id);
|
|
7401
7409
|
}
|
|
7402
7410
|
return o && (o.skipped_count = a), [
|
|
7403
7411
|
r,
|
|
@@ -7405,12 +7413,12 @@ function iu(e, t, n) {
|
|
|
7405
7413
|
o
|
|
7406
7414
|
];
|
|
7407
7415
|
}
|
|
7408
|
-
function
|
|
7409
|
-
let [r, i] =
|
|
7416
|
+
function su(e, t, n) {
|
|
7417
|
+
let [r, i] = ou(e, t, n);
|
|
7410
7418
|
return [r, i];
|
|
7411
7419
|
}
|
|
7412
|
-
var
|
|
7413
|
-
function
|
|
7420
|
+
var cu = /^legacy:memory_item:(.+)$/;
|
|
7421
|
+
function lu(e, t = 2e3) {
|
|
7414
7422
|
let n = N(e, { schema: H }), r = n.select({ device_id: Y.device_id }).from(Y).limit(1).get(), i = String(r?.device_id ?? "").trim();
|
|
7415
7423
|
if (!i) return 0;
|
|
7416
7424
|
let a = n.select({
|
|
@@ -7424,7 +7432,7 @@ function su(e, t = 2e3) {
|
|
|
7424
7432
|
let t = Number(e.id), r = String(e.import_key ?? "").trim(), a = z(e.metadata_json), s = typeof a.clock_device_id == "string" ? a.clock_device_id.trim() : "", c = "";
|
|
7425
7433
|
if (!r) c = `legacy:${i}:memory_item:${t}`;
|
|
7426
7434
|
else {
|
|
7427
|
-
let e = r.match(
|
|
7435
|
+
let e = r.match(cu);
|
|
7428
7436
|
if (!e) continue;
|
|
7429
7437
|
let t = e[1] ?? "", n = s && s !== "local" ? s : i;
|
|
7430
7438
|
c = n ? `legacy:${n}:memory_item:${t}` : "";
|
|
@@ -7435,9 +7443,9 @@ function su(e, t = 2e3) {
|
|
|
7435
7443
|
}
|
|
7436
7444
|
return o;
|
|
7437
7445
|
}
|
|
7438
|
-
function
|
|
7446
|
+
function uu(e, t = 200) {
|
|
7439
7447
|
if (t <= 0) return 0;
|
|
7440
|
-
|
|
7448
|
+
lu(e, 2e3);
|
|
7441
7449
|
let n = N(e, { schema: H }), r = n.select({ device_id: Y.device_id }).from(Y).limit(1).get(), i = String(r?.device_id ?? "").trim(), a = n.select().from(W).where(D(ce(re(W.deleted_at), k(W.active, 0)), M`NOT EXISTS (
|
|
7442
7450
|
SELECT 1
|
|
7443
7451
|
FROM replication_ops ro
|
|
@@ -7462,7 +7470,7 @@ function cu(e, t = 200) {
|
|
|
7462
7470
|
for (let e of s) {
|
|
7463
7471
|
let t = Number(e.id ?? 0);
|
|
7464
7472
|
if (!t) continue;
|
|
7465
|
-
let r = typeof e.metadata_json == "string" ? z(e.metadata_json) :
|
|
7473
|
+
let r = typeof e.metadata_json == "string" ? z(e.metadata_json) : du(e.metadata_json), a = typeof r.clock_device_id == "string" ? r.clock_device_id.trim() : "", o = a && a !== "local" ? a : i, s = String(e.import_key ?? "").trim();
|
|
7466
7474
|
if (!s) {
|
|
7467
7475
|
if (!o) continue;
|
|
7468
7476
|
s = `legacy:${o}:memory_item:${t}`, n.update(W).set({ import_key: s }).where(k(W.id, t)).run();
|
|
@@ -7471,7 +7479,7 @@ function cu(e, t = 200) {
|
|
|
7471
7479
|
if (n.select({ one: M`1` }).from(nn).where(k(nn.op_id, p)).limit(1).get()) continue;
|
|
7472
7480
|
let m = o;
|
|
7473
7481
|
if (!m) continue;
|
|
7474
|
-
let h =
|
|
7482
|
+
let h = fu(e);
|
|
7475
7483
|
n.insert(nn).values({
|
|
7476
7484
|
op_id: p,
|
|
7477
7485
|
entity_type: "memory_item",
|
|
@@ -7487,10 +7495,10 @@ function cu(e, t = 200) {
|
|
|
7487
7495
|
}
|
|
7488
7496
|
return l;
|
|
7489
7497
|
}
|
|
7490
|
-
function
|
|
7498
|
+
function du(e) {
|
|
7491
7499
|
return typeof e == "string" ? z(e) : e && typeof e == "object" ? e : {};
|
|
7492
7500
|
}
|
|
7493
|
-
function
|
|
7501
|
+
function fu(e) {
|
|
7494
7502
|
let t = (e) => {
|
|
7495
7503
|
if (typeof e != "string") return e ?? null;
|
|
7496
7504
|
try {
|
|
@@ -7531,7 +7539,7 @@ function uu(e) {
|
|
|
7531
7539
|
import_key: e.import_key ?? null
|
|
7532
7540
|
};
|
|
7533
7541
|
}
|
|
7534
|
-
function
|
|
7542
|
+
function pu(e, t, n) {
|
|
7535
7543
|
let r = N(e, { schema: H }), i = {
|
|
7536
7544
|
applied: 0,
|
|
7537
7545
|
skipped: 0,
|
|
@@ -7556,14 +7564,14 @@ function du(e, t, n) {
|
|
|
7556
7564
|
metadata_json: W.metadata_json
|
|
7557
7565
|
}).from(W).where(k(W.import_key, t)).get();
|
|
7558
7566
|
if (n) {
|
|
7559
|
-
let a =
|
|
7560
|
-
if (!
|
|
7561
|
-
i.conflicts++,
|
|
7567
|
+
let a = zl(n.metadata_json), o = Gl(n.rev ?? 0, n.updated_at ?? "", a);
|
|
7568
|
+
if (!Kl(Gl(e.clock_rev, e.clock_updated_at, e.clock_device_id), o)) {
|
|
7569
|
+
i.conflicts++, mu(r, e);
|
|
7562
7570
|
continue;
|
|
7563
7571
|
}
|
|
7564
|
-
let s =
|
|
7572
|
+
let s = Ll(e, i.errors);
|
|
7565
7573
|
if (!s) continue;
|
|
7566
|
-
let c =
|
|
7574
|
+
let c = Rl(s.metadata_json, e.clock_device_id);
|
|
7567
7575
|
r.update(W).set({
|
|
7568
7576
|
kind: M`COALESCE(${s.kind}, ${W.kind})`,
|
|
7569
7577
|
title: M`COALESCE(${s.title}, ${W.title})`,
|
|
@@ -7591,9 +7599,9 @@ function du(e, t, n) {
|
|
|
7591
7599
|
files_modified: V(s.files_modified)
|
|
7592
7600
|
}).where(k(W.import_key, t)).run();
|
|
7593
7601
|
} else {
|
|
7594
|
-
let n =
|
|
7602
|
+
let n = Ll(e, i.errors);
|
|
7595
7603
|
if (!n) continue;
|
|
7596
|
-
let a =
|
|
7604
|
+
let a = hu(r, null, e.clock_updated_at), o = Rl(n.metadata_json, e.clock_device_id);
|
|
7597
7605
|
r.insert(W).values({
|
|
7598
7606
|
session_id: a,
|
|
7599
7607
|
kind: n.kind ?? "discovery",
|
|
@@ -7632,9 +7640,9 @@ function du(e, t, n) {
|
|
|
7632
7640
|
metadata_json: W.metadata_json
|
|
7633
7641
|
}).from(W).where(k(W.import_key, t)).limit(1).get();
|
|
7634
7642
|
if (n) {
|
|
7635
|
-
let t =
|
|
7636
|
-
if (!
|
|
7637
|
-
i.conflicts++,
|
|
7643
|
+
let t = Gl(n.rev ?? 1, n.updated_at ?? "", zl(n.metadata_json));
|
|
7644
|
+
if (!Kl(Gl(e.clock_rev, e.clock_updated_at, e.clock_device_id), t)) {
|
|
7645
|
+
i.conflicts++, mu(r, e);
|
|
7638
7646
|
continue;
|
|
7639
7647
|
}
|
|
7640
7648
|
let a = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -7646,16 +7654,16 @@ function du(e, t, n) {
|
|
|
7646
7654
|
}).where(k(W.id, n.id)).run();
|
|
7647
7655
|
}
|
|
7648
7656
|
} else {
|
|
7649
|
-
i.skipped++,
|
|
7657
|
+
i.skipped++, mu(r, e);
|
|
7650
7658
|
continue;
|
|
7651
7659
|
}
|
|
7652
|
-
|
|
7660
|
+
mu(r, e), i.applied++;
|
|
7653
7661
|
} catch (t) {
|
|
7654
7662
|
i.errors.push(`op ${e.op_id}: ${t instanceof Error ? t.message : String(t)}`);
|
|
7655
7663
|
}
|
|
7656
7664
|
})(), i;
|
|
7657
7665
|
}
|
|
7658
|
-
function
|
|
7666
|
+
function mu(e, t) {
|
|
7659
7667
|
e.insert(nn).values({
|
|
7660
7668
|
op_id: t.op_id,
|
|
7661
7669
|
entity_type: t.entity_type,
|
|
@@ -7669,7 +7677,7 @@ function fu(e, t) {
|
|
|
7669
7677
|
created_at: t.created_at
|
|
7670
7678
|
}).onConflictDoNothing().run();
|
|
7671
7679
|
}
|
|
7672
|
-
function
|
|
7680
|
+
function hu(e, t, n) {
|
|
7673
7681
|
if (t != null && e.select({ id: U.id }).from(U).where(k(U.id, t)).get()) return t;
|
|
7674
7682
|
let r = n || (/* @__PURE__ */ new Date()).toISOString(), i = e.insert(U).values({
|
|
7675
7683
|
started_at: r,
|
|
@@ -7682,7 +7690,7 @@ function pu(e, t, n) {
|
|
|
7682
7690
|
}
|
|
7683
7691
|
//#endregion
|
|
7684
7692
|
//#region src/store.ts
|
|
7685
|
-
var
|
|
7693
|
+
var gu = new Set([
|
|
7686
7694
|
"discovery",
|
|
7687
7695
|
"change",
|
|
7688
7696
|
"feature",
|
|
@@ -7691,27 +7699,27 @@ var mu = new Set([
|
|
|
7691
7699
|
"decision",
|
|
7692
7700
|
"exploration"
|
|
7693
7701
|
]);
|
|
7694
|
-
function
|
|
7702
|
+
function _u(e) {
|
|
7695
7703
|
let t = e.trim().toLowerCase();
|
|
7696
|
-
if (!
|
|
7704
|
+
if (!gu.has(t)) throw Error(`Invalid memory kind "${e}". Allowed: ${[...gu].join(", ")}`);
|
|
7697
7705
|
return t;
|
|
7698
7706
|
}
|
|
7699
|
-
function
|
|
7707
|
+
function vu() {
|
|
7700
7708
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
7701
7709
|
}
|
|
7702
|
-
function
|
|
7710
|
+
function yu(e) {
|
|
7703
7711
|
return (e.match(/\?/g) ?? []).length;
|
|
7704
7712
|
}
|
|
7705
|
-
function
|
|
7713
|
+
function bu(e, t) {
|
|
7706
7714
|
let n = e.split("?"), r = M.raw(n[0] ?? "");
|
|
7707
7715
|
for (let e = 1; e < n.length; e++) r = M`${r}${t[e - 1]}${M.raw(n[e] ?? "")}`;
|
|
7708
7716
|
return r;
|
|
7709
7717
|
}
|
|
7710
|
-
function
|
|
7718
|
+
function xu(e, t) {
|
|
7711
7719
|
let n = [], r = 0;
|
|
7712
7720
|
for (let i of e) {
|
|
7713
|
-
let e =
|
|
7714
|
-
n.push(
|
|
7721
|
+
let e = yu(i), a = t.slice(r, r + e);
|
|
7722
|
+
n.push(bu(i, a)), r += e;
|
|
7715
7723
|
}
|
|
7716
7724
|
if (r !== t.length) throw Error("filter parameter mismatch while building SQL clauses");
|
|
7717
7725
|
if (n.length === 1) return n[0] ?? M`1=1`;
|
|
@@ -7724,7 +7732,7 @@ function $(e) {
|
|
|
7724
7732
|
let t = e.trim();
|
|
7725
7733
|
return t.length > 0 ? t : null;
|
|
7726
7734
|
}
|
|
7727
|
-
function
|
|
7735
|
+
function Su(e) {
|
|
7728
7736
|
if (typeof e != "string" || !e.trim()) return [];
|
|
7729
7737
|
try {
|
|
7730
7738
|
let t = JSON.parse(e);
|
|
@@ -7733,21 +7741,21 @@ function bu(e) {
|
|
|
7733
7741
|
return [];
|
|
7734
7742
|
}
|
|
7735
7743
|
}
|
|
7736
|
-
function
|
|
7744
|
+
function Cu(e) {
|
|
7737
7745
|
let t = $(e);
|
|
7738
7746
|
if (!t) return "";
|
|
7739
7747
|
let n = t.replace(/\\/g, "/").split("/").filter(Boolean);
|
|
7740
7748
|
return n[n.length - 1] ?? t;
|
|
7741
7749
|
}
|
|
7742
|
-
var
|
|
7743
|
-
function
|
|
7750
|
+
var wu = "Legacy synced peer", Tu = "shared:legacy";
|
|
7751
|
+
function Eu(e) {
|
|
7744
7752
|
let { metadata_json: t, ...n } = e;
|
|
7745
7753
|
return {
|
|
7746
7754
|
...n,
|
|
7747
7755
|
metadata_json: z(t)
|
|
7748
7756
|
};
|
|
7749
7757
|
}
|
|
7750
|
-
var
|
|
7758
|
+
var Du = class {
|
|
7751
7759
|
db;
|
|
7752
7760
|
dbPath;
|
|
7753
7761
|
deviceId;
|
|
@@ -7789,10 +7797,10 @@ var Tu = class {
|
|
|
7789
7797
|
}
|
|
7790
7798
|
get(e) {
|
|
7791
7799
|
let t = this.d.select().from(W).where(k(W.id, e)).get();
|
|
7792
|
-
return t ?
|
|
7800
|
+
return t ? Eu(t) : null;
|
|
7793
7801
|
}
|
|
7794
7802
|
startSession(e) {
|
|
7795
|
-
let t =
|
|
7803
|
+
let t = vu(), n = this.d.insert(U).values({
|
|
7796
7804
|
started_at: t,
|
|
7797
7805
|
cwd: e.cwd ?? process.cwd(),
|
|
7798
7806
|
project: e.project ?? null,
|
|
@@ -7806,7 +7814,7 @@ var Tu = class {
|
|
|
7806
7814
|
return n;
|
|
7807
7815
|
}
|
|
7808
7816
|
endSession(e, t) {
|
|
7809
|
-
let n =
|
|
7817
|
+
let n = vu();
|
|
7810
7818
|
if (t) {
|
|
7811
7819
|
let r = {
|
|
7812
7820
|
...z(this.d.select({ metadata_json: U.metadata_json }).from(U).where(k(U.id, e)).get()?.metadata_json),
|
|
@@ -7819,7 +7827,7 @@ var Tu = class {
|
|
|
7819
7827
|
} else this.d.update(U).set({ ended_at: n }).where(k(U.id, e)).run();
|
|
7820
7828
|
}
|
|
7821
7829
|
remember(e, t, n, r, i = .5, o, s) {
|
|
7822
|
-
let c =
|
|
7830
|
+
let c = _u(t), l = vu(), u = o ? [...new Set(o)].sort().join(" ") : "", d = { ...s ?? {} };
|
|
7823
7831
|
d.clock_device_id ??= this.deviceId;
|
|
7824
7832
|
let f = d.import_key || a();
|
|
7825
7833
|
d.import_key = f;
|
|
@@ -7856,7 +7864,7 @@ var Tu = class {
|
|
|
7856
7864
|
}).returning({ id: W.id }).all()[0]?.id;
|
|
7857
7865
|
if (S == null) throw Error("memory insert returned no id");
|
|
7858
7866
|
try {
|
|
7859
|
-
|
|
7867
|
+
ql(this.db, {
|
|
7860
7868
|
memoryId: S,
|
|
7861
7869
|
opType: "upsert",
|
|
7862
7870
|
deviceId: this.deviceId
|
|
@@ -7904,7 +7912,7 @@ var Tu = class {
|
|
|
7904
7912
|
if (!t) return;
|
|
7905
7913
|
let n = z(t.metadata_json);
|
|
7906
7914
|
n.clock_device_id = this.deviceId;
|
|
7907
|
-
let r =
|
|
7915
|
+
let r = vu(), i = (t.rev ?? 0) + 1;
|
|
7908
7916
|
this.d.update(W).set({
|
|
7909
7917
|
active: 0,
|
|
7910
7918
|
deleted_at: r,
|
|
@@ -7913,7 +7921,7 @@ var Tu = class {
|
|
|
7913
7921
|
rev: i
|
|
7914
7922
|
}).where(k(W.id, e)).run();
|
|
7915
7923
|
try {
|
|
7916
|
-
|
|
7924
|
+
ql(this.db, {
|
|
7917
7925
|
memoryId: e,
|
|
7918
7926
|
opType: "delete",
|
|
7919
7927
|
deviceId: this.deviceId
|
|
@@ -7922,20 +7930,20 @@ var Tu = class {
|
|
|
7922
7930
|
}).immediate();
|
|
7923
7931
|
}
|
|
7924
7932
|
recent(e = 10, t, n = 0) {
|
|
7925
|
-
let r = ["memory_items.active = 1"], i = Oa(t), a =
|
|
7933
|
+
let r = ["memory_items.active = 1"], i = Oa(t), a = xu([...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");
|
|
7926
7934
|
return this.d.all(M`SELECT memory_items.* FROM ${o}
|
|
7927
7935
|
WHERE ${a}
|
|
7928
7936
|
ORDER BY created_at DESC
|
|
7929
|
-
LIMIT ${e} OFFSET ${Math.max(n, 0)}`).map((e) =>
|
|
7937
|
+
LIMIT ${e} OFFSET ${Math.max(n, 0)}`).map((e) => Eu(e));
|
|
7930
7938
|
}
|
|
7931
7939
|
recentByKinds(e, t = 10, n, r = 0) {
|
|
7932
7940
|
let i = e.filter((e) => e.length > 0);
|
|
7933
7941
|
if (i.length === 0) return [];
|
|
7934
|
-
let a = ["memory_items.active = 1", `memory_items.kind IN (${i.map(() => "?").join(", ")})`], o = Oa(n), s =
|
|
7942
|
+
let a = ["memory_items.active = 1", `memory_items.kind IN (${i.map(() => "?").join(", ")})`], o = Oa(n), s = xu([...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");
|
|
7935
7943
|
return this.d.all(M`SELECT memory_items.* FROM ${c}
|
|
7936
7944
|
WHERE ${s}
|
|
7937
7945
|
ORDER BY created_at DESC
|
|
7938
|
-
LIMIT ${t} OFFSET ${Math.max(r, 0)}`).map((e) =>
|
|
7946
|
+
LIMIT ${t} OFFSET ${Math.max(r, 0)}`).map((e) => Eu(e));
|
|
7939
7947
|
}
|
|
7940
7948
|
stats() {
|
|
7941
7949
|
let e = (e) => this.d.select({ c: M`COUNT(*)` }).from(e).get()?.c ?? 0, t = e(W), n = this.d.select({ c: M`COUNT(*)` }).from(W).where(k(W.active, 1)).get()?.c ?? 0, r = e(U), i = e(Zt), a = e(G), o = 0;
|
|
@@ -8000,7 +8008,7 @@ var Tu = class {
|
|
|
8000
8008
|
if (!this.memoryOwnedBySelf(t)) throw Error("memory not owned by this device");
|
|
8001
8009
|
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 = z(t.metadata_json);
|
|
8002
8010
|
o.visibility = n, o.workspace_kind = i, o.workspace_id = a, o.clock_device_id = this.deviceId;
|
|
8003
|
-
let s =
|
|
8011
|
+
let s = vu(), c = (t.rev ?? 0) + 1;
|
|
8004
8012
|
this.d.update(W).set({
|
|
8005
8013
|
visibility: n,
|
|
8006
8014
|
workspace_kind: i,
|
|
@@ -8010,7 +8018,7 @@ var Tu = class {
|
|
|
8010
8018
|
rev: c
|
|
8011
8019
|
}).where(k(W.id, e)).run();
|
|
8012
8020
|
try {
|
|
8013
|
-
|
|
8021
|
+
ql(this.db, {
|
|
8014
8022
|
memoryId: e,
|
|
8015
8023
|
opType: "upsert",
|
|
8016
8024
|
deviceId: this.deviceId
|
|
@@ -8022,19 +8030,19 @@ var Tu = class {
|
|
|
8022
8030
|
}).immediate();
|
|
8023
8031
|
}
|
|
8024
8032
|
search(e, t = 10, n) {
|
|
8025
|
-
return
|
|
8033
|
+
return Fc(this, e, t, n);
|
|
8026
8034
|
}
|
|
8027
8035
|
timeline(e, t, n = 3, r = 3, i) {
|
|
8028
|
-
return
|
|
8036
|
+
return Lc(this, e, t, n, r, i);
|
|
8029
8037
|
}
|
|
8030
8038
|
explain(e, t, n = 10, r, i) {
|
|
8031
|
-
return
|
|
8039
|
+
return Uc(this, e, t, n, r, i);
|
|
8032
8040
|
}
|
|
8033
8041
|
buildMemoryPack(e, t, n, r) {
|
|
8034
|
-
return
|
|
8042
|
+
return wl(this, e, t, n ?? null, r);
|
|
8035
8043
|
}
|
|
8036
8044
|
async buildMemoryPackAsync(e, t, n, r) {
|
|
8037
|
-
return
|
|
8045
|
+
return Tl(this, e, t, n ?? null, r);
|
|
8038
8046
|
}
|
|
8039
8047
|
normalizeStreamIdentity(e, t) {
|
|
8040
8048
|
let n = e.trim().toLowerCase() || "opencode", r = t.trim();
|
|
@@ -8218,7 +8226,7 @@ var Tu = class {
|
|
|
8218
8226
|
}).run();
|
|
8219
8227
|
}
|
|
8220
8228
|
updateRawEventIngestStats(e, t, n, r) {
|
|
8221
|
-
let i =
|
|
8229
|
+
let i = vu(), a = t + n + r;
|
|
8222
8230
|
this.d.insert(on).values({
|
|
8223
8231
|
created_at: i,
|
|
8224
8232
|
inserted_events: e,
|
|
@@ -8251,7 +8259,7 @@ var Tu = class {
|
|
|
8251
8259
|
if (!e.eventType.trim()) throw Error("event_type is required");
|
|
8252
8260
|
let [t, n] = this.normalizeStreamIdentity(e.source ?? "opencode", e.opencodeSessionId);
|
|
8253
8261
|
return this.db.transaction(() => {
|
|
8254
|
-
let r =
|
|
8262
|
+
let r = vu();
|
|
8255
8263
|
if (this.d.select({ one: M`1` }).from(G).where(D(k(G.source, t), k(G.stream_id, n), k(G.event_id, e.eventId))).get() != null) return this.updateRawEventIngestStats(0, 0, 1, 0), !1;
|
|
8256
8264
|
this.d.select({ one: M`1` }).from(K).where(D(k(K.source, t), k(K.stream_id, n))).get() ?? this.d.insert(K).values({
|
|
8257
8265
|
opencode_session_id: n,
|
|
@@ -8283,7 +8291,7 @@ var Tu = class {
|
|
|
8283
8291
|
if (!e.trim()) throw Error("opencode_session_id is required");
|
|
8284
8292
|
let [n, r] = this.normalizeStreamIdentity("opencode", e);
|
|
8285
8293
|
return this.db.transaction(() => {
|
|
8286
|
-
let e =
|
|
8294
|
+
let e = vu();
|
|
8287
8295
|
this.d.select({ one: M`1` }).from(K).where(D(k(K.source, n), k(K.stream_id, r))).get() ?? this.d.insert(K).values({
|
|
8288
8296
|
opencode_session_id: r,
|
|
8289
8297
|
source: n,
|
|
@@ -8352,7 +8360,7 @@ var Tu = class {
|
|
|
8352
8360
|
})();
|
|
8353
8361
|
}
|
|
8354
8362
|
updateRawEventSessionMeta(e) {
|
|
8355
|
-
let [t, n] = this.normalizeStreamIdentity(e.source ?? "opencode", e.opencodeSessionId), r =
|
|
8363
|
+
let [t, n] = this.normalizeStreamIdentity(e.source ?? "opencode", e.opencodeSessionId), r = vu(), i = K;
|
|
8356
8364
|
this.d.insert(i).values({
|
|
8357
8365
|
opencode_session_id: n,
|
|
8358
8366
|
source: t,
|
|
@@ -8452,8 +8460,8 @@ var Tu = class {
|
|
|
8452
8460
|
${W.actor_id} IS NULL
|
|
8453
8461
|
OR TRIM(${W.actor_id}) = ''
|
|
8454
8462
|
OR ${W.actor_id} LIKE 'legacy-sync:%'
|
|
8455
|
-
OR ${W.actor_display_name} = ${
|
|
8456
|
-
OR ${W.workspace_id} = ${
|
|
8463
|
+
OR ${W.actor_display_name} = ${wu}
|
|
8464
|
+
OR ${W.workspace_id} = ${Tu}
|
|
8457
8465
|
OR ${W.trust_state} = 'legacy_unknown'
|
|
8458
8466
|
)
|
|
8459
8467
|
)`, M`${W.origin_device_id} != ${this.deviceId}`, M`${W.origin_device_id} NOT IN (
|
|
@@ -8467,13 +8475,13 @@ var Tu = class {
|
|
|
8467
8475
|
}));
|
|
8468
8476
|
}
|
|
8469
8477
|
effectiveSyncProjectFilters(e) {
|
|
8470
|
-
let t = tt(), n =
|
|
8478
|
+
let t = tt(), n = Su(JSON.stringify(t.sync_projects_include ?? [])), r = Su(JSON.stringify(t.sync_projects_exclude ?? []));
|
|
8471
8479
|
if (e) {
|
|
8472
8480
|
let t = this.d.select({
|
|
8473
8481
|
projects_include_json: J.projects_include_json,
|
|
8474
8482
|
projects_exclude_json: J.projects_exclude_json
|
|
8475
8483
|
}).from(J).where(k(J.peer_device_id, e)).limit(1).get();
|
|
8476
|
-
t && (t.projects_include_json != null && (n =
|
|
8484
|
+
t && (t.projects_include_json != null && (n = Su(t.projects_include_json)), t.projects_exclude_json != null && (r = Su(t.projects_exclude_json)));
|
|
8477
8485
|
}
|
|
8478
8486
|
return {
|
|
8479
8487
|
include: n,
|
|
@@ -8481,7 +8489,7 @@ var Tu = class {
|
|
|
8481
8489
|
};
|
|
8482
8490
|
}
|
|
8483
8491
|
syncProjectAllowed(e, t) {
|
|
8484
|
-
let { include: n, exclude: r } = this.effectiveSyncProjectFilters(t), i = $(e), a =
|
|
8492
|
+
let { include: n, exclude: r } = this.effectiveSyncProjectFilters(t), i = $(e), a = Cu(i);
|
|
8485
8493
|
return !(n.length > 0 && !n.some((e) => e === i || e === a) || r.some((e) => e === i || e === a));
|
|
8486
8494
|
}
|
|
8487
8495
|
sharingReviewSummary(e) {
|
|
@@ -8501,7 +8509,7 @@ var Tu = class {
|
|
|
8501
8509
|
if (!n || !r || r === this.actorId) continue;
|
|
8502
8510
|
let i = $(e.project);
|
|
8503
8511
|
if (t) {
|
|
8504
|
-
let e =
|
|
8512
|
+
let e = Cu(t), n = Cu(i);
|
|
8505
8513
|
if (i !== t && n !== e) continue;
|
|
8506
8514
|
}
|
|
8507
8515
|
if (!this.syncProjectAllowed(i, n)) continue;
|
|
@@ -8525,11 +8533,11 @@ var Tu = class {
|
|
|
8525
8533
|
close() {
|
|
8526
8534
|
this.db.close();
|
|
8527
8535
|
}
|
|
8528
|
-
},
|
|
8529
|
-
function
|
|
8536
|
+
}, Ou = "_codemem._tcp.local.";
|
|
8537
|
+
function ku(e) {
|
|
8530
8538
|
return e.mdns.length === 0 ? Mi(e.stored, []) : Mi(e.mdns, e.stored);
|
|
8531
8539
|
}
|
|
8532
|
-
function
|
|
8540
|
+
function Au(e, t) {
|
|
8533
8541
|
let n = N(e, { schema: H }).select({ addresses_json: J.addresses_json }).from(J).where(k(J.peer_device_id, t)).get();
|
|
8534
8542
|
if (!n?.addresses_json) return [];
|
|
8535
8543
|
try {
|
|
@@ -8539,8 +8547,8 @@ function Ou(e, t) {
|
|
|
8539
8547
|
return [];
|
|
8540
8548
|
}
|
|
8541
8549
|
}
|
|
8542
|
-
function
|
|
8543
|
-
let i = Mi(
|
|
8550
|
+
function ju(e, t, n, r) {
|
|
8551
|
+
let i = Mi(Au(e, t), n), a = (/* @__PURE__ */ new Date()).toISOString(), o = JSON.stringify(i);
|
|
8544
8552
|
return N(e, { schema: H }).insert(J).values({
|
|
8545
8553
|
peer_device_id: t,
|
|
8546
8554
|
name: r?.name ?? null,
|
|
@@ -8560,7 +8568,7 @@ function ku(e, t, n, r) {
|
|
|
8560
8568
|
}
|
|
8561
8569
|
}).run(), i;
|
|
8562
8570
|
}
|
|
8563
|
-
function
|
|
8571
|
+
function Mu(e, t, n) {
|
|
8564
8572
|
let r = N(e, { schema: H }), i = (/* @__PURE__ */ new Date()).toISOString();
|
|
8565
8573
|
r.insert(X).values({
|
|
8566
8574
|
peer_device_id: t,
|
|
@@ -8575,32 +8583,32 @@ function Au(e, t, n) {
|
|
|
8575
8583
|
last_error: null
|
|
8576
8584
|
}).where(k(J.peer_device_id, t)).run() : r.update(J).set({ last_error: n.error ?? null }).where(k(J.peer_device_id, t)).run();
|
|
8577
8585
|
}
|
|
8578
|
-
function
|
|
8579
|
-
let r =
|
|
8586
|
+
function Nu(e, t, n) {
|
|
8587
|
+
let r = Au(e, t), i = Ai(n ?? ""), a = r;
|
|
8580
8588
|
return i && (a = [i, ...r.filter((e) => Ai(e) !== i)], N(e, { schema: H }).update(J).set({
|
|
8581
8589
|
addresses_json: JSON.stringify(a),
|
|
8582
8590
|
last_sync_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
8583
8591
|
last_error: null
|
|
8584
8592
|
}).where(k(J.peer_device_id, t)).run()), a;
|
|
8585
8593
|
}
|
|
8586
|
-
function
|
|
8594
|
+
function Pu(e, t, n) {
|
|
8587
8595
|
let r = n.include === null ? null : JSON.stringify(n.include), i = n.exclude === null ? null : JSON.stringify(n.exclude);
|
|
8588
8596
|
N(e, { schema: H }).update(J).set({
|
|
8589
8597
|
projects_include_json: r,
|
|
8590
8598
|
projects_exclude_json: i
|
|
8591
8599
|
}).where(k(J.peer_device_id, t)).run();
|
|
8592
8600
|
}
|
|
8593
|
-
function
|
|
8601
|
+
function Fu(e, t, n) {
|
|
8594
8602
|
N(e, { schema: H }).update(J).set({ claimed_local_actor: n ? 1 : 0 }).where(k(J.peer_device_id, t)).run();
|
|
8595
8603
|
}
|
|
8596
|
-
function
|
|
8604
|
+
function Iu(e) {
|
|
8597
8605
|
try {
|
|
8598
8606
|
return fe("which", [e], { stdio: "pipe" }), !0;
|
|
8599
8607
|
} catch {
|
|
8600
8608
|
return !1;
|
|
8601
8609
|
}
|
|
8602
8610
|
}
|
|
8603
|
-
function
|
|
8611
|
+
function Lu(e, t = 1200) {
|
|
8604
8612
|
try {
|
|
8605
8613
|
return fe("dns-sd", e, {
|
|
8606
8614
|
encoding: "utf8",
|
|
@@ -8619,8 +8627,8 @@ function Fu(e, t = 1200) {
|
|
|
8619
8627
|
return "";
|
|
8620
8628
|
}
|
|
8621
8629
|
}
|
|
8622
|
-
function
|
|
8623
|
-
let e =
|
|
8630
|
+
function Ru() {
|
|
8631
|
+
let e = Lu([
|
|
8624
8632
|
"-B",
|
|
8625
8633
|
"_codemem._tcp",
|
|
8626
8634
|
"local."
|
|
@@ -8639,8 +8647,8 @@ function Iu() {
|
|
|
8639
8647
|
}
|
|
8640
8648
|
return [...t];
|
|
8641
8649
|
}
|
|
8642
|
-
function
|
|
8643
|
-
let t =
|
|
8650
|
+
function zu(e) {
|
|
8651
|
+
let t = Lu([
|
|
8644
8652
|
"-L",
|
|
8645
8653
|
e,
|
|
8646
8654
|
"_codemem._tcp",
|
|
@@ -8657,12 +8665,12 @@ function Lu(e) {
|
|
|
8657
8665
|
properties: s
|
|
8658
8666
|
};
|
|
8659
8667
|
}
|
|
8660
|
-
function
|
|
8668
|
+
function Bu() {
|
|
8661
8669
|
let e = process.env.CODEMEM_SYNC_MDNS;
|
|
8662
8670
|
return e ? e === "1" || e.toLowerCase() === "true" : !1;
|
|
8663
8671
|
}
|
|
8664
|
-
function
|
|
8665
|
-
if (!
|
|
8672
|
+
function Vu(e, t) {
|
|
8673
|
+
if (!Bu() || process.platform !== "darwin" || !Iu("dns-sd")) return { close() {} };
|
|
8666
8674
|
let n = pe("dns-sd", [
|
|
8667
8675
|
"-R",
|
|
8668
8676
|
`codemem-${e.slice(0, 12)}`,
|
|
@@ -8680,18 +8688,18 @@ function zu(e, t) {
|
|
|
8680
8688
|
} catch {}
|
|
8681
8689
|
} };
|
|
8682
8690
|
}
|
|
8683
|
-
function
|
|
8684
|
-
if (!
|
|
8685
|
-
let e =
|
|
8691
|
+
function Hu() {
|
|
8692
|
+
if (!Bu() || process.platform !== "darwin" || !Iu("dns-sd")) return [];
|
|
8693
|
+
let e = Ru();
|
|
8686
8694
|
if (e.length === 0) return [];
|
|
8687
8695
|
let t = [];
|
|
8688
8696
|
for (let n of e) {
|
|
8689
|
-
let e =
|
|
8697
|
+
let e = zu(n);
|
|
8690
8698
|
e && t.push(e);
|
|
8691
8699
|
}
|
|
8692
8700
|
return t;
|
|
8693
8701
|
}
|
|
8694
|
-
function
|
|
8702
|
+
function Uu(e, t) {
|
|
8695
8703
|
let n = [];
|
|
8696
8704
|
for (let r of t) {
|
|
8697
8705
|
let t = r.properties ?? {}, i = t.device_id ?? t.device_id;
|
|
@@ -8705,19 +8713,19 @@ function Vu(e, t) {
|
|
|
8705
8713
|
}
|
|
8706
8714
|
//#endregion
|
|
8707
8715
|
//#region src/sync-pass.ts
|
|
8708
|
-
var
|
|
8709
|
-
function
|
|
8716
|
+
var Wu = 1048576, Gu = 200;
|
|
8717
|
+
function Ku(e, t) {
|
|
8710
8718
|
return !t || !t.includes("|") ? !1 : e ? t > e : !0;
|
|
8711
8719
|
}
|
|
8712
|
-
function
|
|
8720
|
+
function qu(e) {
|
|
8713
8721
|
if (!e) return null;
|
|
8714
8722
|
let t = e.error, n = e.reason;
|
|
8715
8723
|
return typeof t == "string" && typeof n == "string" ? `${t}:${n}` : typeof t == "string" ? t : null;
|
|
8716
8724
|
}
|
|
8717
|
-
function
|
|
8725
|
+
function Ju(e) {
|
|
8718
8726
|
return e.length === 0 ? null : `all addresses failed | ${e.map((e) => `${e.address}: ${e.error}`).join(" || ")}`;
|
|
8719
8727
|
}
|
|
8720
|
-
function
|
|
8728
|
+
function Yu(e, t, n) {
|
|
8721
8729
|
let r = N(e, { schema: H }), i = (/* @__PURE__ */ new Date()).toISOString();
|
|
8722
8730
|
r.insert(X).values({
|
|
8723
8731
|
peer_device_id: t,
|
|
@@ -8729,7 +8737,7 @@ function qu(e, t, n) {
|
|
|
8729
8737
|
error: n.error ?? null
|
|
8730
8738
|
}).run();
|
|
8731
8739
|
}
|
|
8732
|
-
function
|
|
8740
|
+
function Xu(e, t) {
|
|
8733
8741
|
let n = N(e, { schema: H }), r = (/* @__PURE__ */ new Date()).toISOString();
|
|
8734
8742
|
n.update(J).set({
|
|
8735
8743
|
last_sync_at: r,
|
|
@@ -8737,7 +8745,7 @@ function Ju(e, t) {
|
|
|
8737
8745
|
last_error: null
|
|
8738
8746
|
}).where(k(J.peer_device_id, t)).run();
|
|
8739
8747
|
}
|
|
8740
|
-
function
|
|
8748
|
+
function Zu(e, t, n, r) {
|
|
8741
8749
|
let i = N(e, { schema: H }), { replicationOps: a } = H, o;
|
|
8742
8750
|
if (t) {
|
|
8743
8751
|
let e = t.indexOf("|"), s = e >= 0 ? t.slice(0, e) : t, c = e >= 0 ? t.slice(e + 1) : "";
|
|
@@ -8749,8 +8757,8 @@ function Yu(e, t, n, r) {
|
|
|
8749
8757
|
let c = `${s.created_at}|${s.op_id}`;
|
|
8750
8758
|
return [o, c];
|
|
8751
8759
|
}
|
|
8752
|
-
var
|
|
8753
|
-
async function
|
|
8760
|
+
var Qu = 8;
|
|
8761
|
+
async function $u(e, t, n, r, i = 0) {
|
|
8754
8762
|
if (n.length === 0) return;
|
|
8755
8763
|
let a = { ops: n }, o = Buffer.from(JSON.stringify(a), "utf-8"), [s, c] = await Dn("POST", e, {
|
|
8756
8764
|
headers: _i({
|
|
@@ -8764,20 +8772,20 @@ async function Zu(e, t, n, r, i = 0) {
|
|
|
8764
8772
|
bodyBytes: o
|
|
8765
8773
|
});
|
|
8766
8774
|
if (s === 200 && c != null) return;
|
|
8767
|
-
let l =
|
|
8768
|
-
if (s === 413 && n.length > 1 && i <
|
|
8775
|
+
let l = qu(c);
|
|
8776
|
+
if (s === 413 && n.length > 1 && i < Qu && (l === "payload_too_large" || l === "too_many_ops")) {
|
|
8769
8777
|
let a = Math.floor(n.length / 2);
|
|
8770
|
-
await
|
|
8778
|
+
await $u(e, t, n.slice(0, a), r, i + 1), await $u(e, t, n.slice(a), r, i + 1);
|
|
8771
8779
|
return;
|
|
8772
8780
|
}
|
|
8773
8781
|
let u = l ? ` (${s}: ${l})` : ` (${s})`;
|
|
8774
8782
|
throw Error(`peer ops push failed${u}`);
|
|
8775
8783
|
}
|
|
8776
|
-
function
|
|
8777
|
-
|
|
8784
|
+
function ed(e) {
|
|
8785
|
+
lu(e, 2e3), uu(e, 200);
|
|
8778
8786
|
}
|
|
8779
|
-
async function
|
|
8780
|
-
let i = r?.limit ??
|
|
8787
|
+
async function td(e, t, n, r) {
|
|
8788
|
+
let i = r?.limit ?? Gu, a = r?.keysDir, o = N(e, { schema: H }).select({ pinned_fingerprint: J.pinned_fingerprint }).from(J).where(k(J.peer_device_id, t)).get()?.pinned_fingerprint ?? "";
|
|
8781
8789
|
if (!o) return {
|
|
8782
8790
|
ok: !1,
|
|
8783
8791
|
error: "peer not pinned",
|
|
@@ -8785,12 +8793,12 @@ async function $u(e, t, n, r) {
|
|
|
8785
8793
|
opsOut: 0,
|
|
8786
8794
|
addressErrors: []
|
|
8787
8795
|
};
|
|
8788
|
-
let [s, c] =
|
|
8796
|
+
let [s, c] = Vl(e, t), l;
|
|
8789
8797
|
try {
|
|
8790
8798
|
[l] = Jn(e, { keysDir: a });
|
|
8791
8799
|
} catch (n) {
|
|
8792
8800
|
let r = `device identity unavailable: ${n instanceof Error ? n.message.trim() || n.constructor.name : "unknown"}`;
|
|
8793
|
-
return
|
|
8801
|
+
return Yu(e, t, {
|
|
8794
8802
|
ok: !1,
|
|
8795
8803
|
error: r
|
|
8796
8804
|
}), {
|
|
@@ -8815,7 +8823,7 @@ async function $u(e, t, n, r) {
|
|
|
8815
8823
|
keysDir: a
|
|
8816
8824
|
}) });
|
|
8817
8825
|
if (u !== 200 || !d) {
|
|
8818
|
-
let e =
|
|
8826
|
+
let e = qu(d), t = e ? ` (${u}: ${e})` : ` (${u})`;
|
|
8819
8827
|
throw Error(`peer status failed${t}`);
|
|
8820
8828
|
}
|
|
8821
8829
|
if (d.fingerprint !== o) throw Error("peer fingerprint mismatch");
|
|
@@ -8830,19 +8838,19 @@ async function $u(e, t, n, r) {
|
|
|
8830
8838
|
keysDir: a
|
|
8831
8839
|
}) });
|
|
8832
8840
|
if (p !== 200 || m == null) {
|
|
8833
|
-
let e =
|
|
8841
|
+
let e = qu(m), t = e ? ` (${p}: ${e})` : ` (${p})`;
|
|
8834
8842
|
throw Error(`peer ops fetch failed${t}`);
|
|
8835
8843
|
}
|
|
8836
8844
|
if (!Array.isArray(m.ops)) throw Error("invalid ops response");
|
|
8837
|
-
let [h, g] =
|
|
8838
|
-
|
|
8839
|
-
let [y, b] =
|
|
8845
|
+
let [h, g] = ou(e, Wl(m), t), _ = pu(e, h, l), v = g || (typeof m.next_cursor == "string" ? m.next_cursor.trim() : "");
|
|
8846
|
+
Ku(s, v) && (Hl(e, t, { lastApplied: v }), s = v);
|
|
8847
|
+
let [y, b] = Zu(e, c, l, i), [x, S] = su(e, y, t), C = `${n}/v1/ops`;
|
|
8840
8848
|
if (x.length > 0) {
|
|
8841
|
-
let e =
|
|
8842
|
-
for (let t of e) await
|
|
8849
|
+
let e = Bl(x, Wu);
|
|
8850
|
+
for (let t of e) await $u(C, l, t, a);
|
|
8843
8851
|
}
|
|
8844
8852
|
let w = S ?? b;
|
|
8845
|
-
return w &&
|
|
8853
|
+
return w && Ku(c, w) && (Hl(e, t, { lastAcked: w }), c = w), Xu(e, t), Yu(e, t, {
|
|
8846
8854
|
ok: !0,
|
|
8847
8855
|
opsIn: _.applied,
|
|
8848
8856
|
opsOut: x.length
|
|
@@ -8862,8 +8870,8 @@ async function $u(e, t, n, r) {
|
|
|
8862
8870
|
}
|
|
8863
8871
|
}
|
|
8864
8872
|
}
|
|
8865
|
-
let f =
|
|
8866
|
-
return d || (f = "no dialable peer addresses"), f ||= "sync failed without diagnostic detail",
|
|
8873
|
+
let f = Ju(u);
|
|
8874
|
+
return d || (f = "no dialable peer addresses"), f ||= "sync failed without diagnostic detail", Yu(e, t, {
|
|
8867
8875
|
ok: !1,
|
|
8868
8876
|
error: f
|
|
8869
8877
|
}), {
|
|
@@ -8874,15 +8882,15 @@ async function $u(e, t, n, r) {
|
|
|
8874
8882
|
addressErrors: u
|
|
8875
8883
|
};
|
|
8876
8884
|
}
|
|
8877
|
-
async function
|
|
8885
|
+
async function nd(e, t, n) {
|
|
8878
8886
|
let r = N(e, { schema: H }).select({ addresses_json: J.addresses_json }).from(J).where(k(J.peer_device_id, t)).get(), i = [];
|
|
8879
8887
|
if (r?.addresses_json) try {
|
|
8880
8888
|
let e = JSON.parse(r.addresses_json);
|
|
8881
8889
|
Array.isArray(e) && (i = e.filter((e) => typeof e == "string"));
|
|
8882
8890
|
} catch {}
|
|
8883
|
-
return
|
|
8891
|
+
return td(e, t, i, n);
|
|
8884
8892
|
}
|
|
8885
|
-
var
|
|
8893
|
+
var rd = [
|
|
8886
8894
|
"no route to host",
|
|
8887
8895
|
"connection refused",
|
|
8888
8896
|
"network is unreachable",
|
|
@@ -8893,33 +8901,33 @@ var td = [
|
|
|
8893
8901
|
"errno 61",
|
|
8894
8902
|
"errno 60",
|
|
8895
8903
|
"errno 111"
|
|
8896
|
-
],
|
|
8897
|
-
function
|
|
8904
|
+
], id = 120, ad = 1800;
|
|
8905
|
+
function od(e) {
|
|
8898
8906
|
if (!e) return !1;
|
|
8899
8907
|
let t = e.toLowerCase();
|
|
8900
|
-
return
|
|
8908
|
+
return rd.some((e) => t.includes(e));
|
|
8901
8909
|
}
|
|
8902
|
-
function
|
|
8910
|
+
function sd(e, t, n = 10) {
|
|
8903
8911
|
let r = N(e, { schema: H }).select({
|
|
8904
8912
|
ok: X.ok,
|
|
8905
8913
|
error: X.error
|
|
8906
8914
|
}).from(X).where(k(X.peer_device_id, t)).orderBy(O(X.started_at)).limit(n).all(), i = 0;
|
|
8907
8915
|
for (let e of r) {
|
|
8908
8916
|
if (e.ok) break;
|
|
8909
|
-
if (
|
|
8917
|
+
if (od(e.error)) i++;
|
|
8910
8918
|
else break;
|
|
8911
8919
|
}
|
|
8912
8920
|
return i;
|
|
8913
8921
|
}
|
|
8914
|
-
function
|
|
8922
|
+
function cd(e) {
|
|
8915
8923
|
if (e <= 1) return 0;
|
|
8916
8924
|
let t = Math.min(e - 1, 8);
|
|
8917
|
-
return Math.min(
|
|
8925
|
+
return Math.min(id * 2 ** (t - 1), ad) * (.5 + Math.random() * .5);
|
|
8918
8926
|
}
|
|
8919
|
-
function
|
|
8920
|
-
let n =
|
|
8927
|
+
function ld(e, t) {
|
|
8928
|
+
let n = sd(e, t);
|
|
8921
8929
|
if (n < 2) return !1;
|
|
8922
|
-
let r =
|
|
8930
|
+
let r = cd(n);
|
|
8923
8931
|
if (r <= 0) return !1;
|
|
8924
8932
|
let i = N(e, { schema: H }).select({ started_at: X.started_at }).from(X).where(k(X.peer_device_id, t)).orderBy(O(X.started_at)).limit(1).get();
|
|
8925
8933
|
if (!i?.started_at) return !1;
|
|
@@ -8932,7 +8940,7 @@ function sd(e, t) {
|
|
|
8932
8940
|
}
|
|
8933
8941
|
//#endregion
|
|
8934
8942
|
//#region src/sync-daemon.ts
|
|
8935
|
-
function
|
|
8943
|
+
function ud(e) {
|
|
8936
8944
|
let t = N(e, { schema: H }), n = (/* @__PURE__ */ new Date()).toISOString();
|
|
8937
8945
|
t.insert(Z).values({
|
|
8938
8946
|
id: 1,
|
|
@@ -8942,7 +8950,7 @@ function cd(e) {
|
|
|
8942
8950
|
set: { last_ok_at: M`excluded.last_ok_at` }
|
|
8943
8951
|
}).run();
|
|
8944
8952
|
}
|
|
8945
|
-
function
|
|
8953
|
+
function dd(e, t, n) {
|
|
8946
8954
|
let r = N(e, { schema: H }), i = (/* @__PURE__ */ new Date()).toISOString();
|
|
8947
8955
|
r.insert(Z).values({
|
|
8948
8956
|
id: 1,
|
|
@@ -8958,14 +8966,14 @@ function ld(e, t, n) {
|
|
|
8958
8966
|
}
|
|
8959
8967
|
}).run();
|
|
8960
8968
|
}
|
|
8961
|
-
async function
|
|
8969
|
+
async function fd(e, t) {
|
|
8962
8970
|
let n = N(e, { schema: H }).select({ peer_device_id: J.peer_device_id }).from(J).all();
|
|
8963
8971
|
if (n.length === 0) return [];
|
|
8964
|
-
|
|
8972
|
+
ed(e);
|
|
8965
8973
|
let r = [];
|
|
8966
8974
|
for (let i of n) {
|
|
8967
8975
|
let n = i.peer_device_id;
|
|
8968
|
-
if (
|
|
8976
|
+
if (ld(e, n)) {
|
|
8969
8977
|
r.push({
|
|
8970
8978
|
ok: !1,
|
|
8971
8979
|
skipped: !0,
|
|
@@ -8973,7 +8981,7 @@ async function ud(e, t) {
|
|
|
8973
8981
|
});
|
|
8974
8982
|
continue;
|
|
8975
8983
|
}
|
|
8976
|
-
let a = await
|
|
8984
|
+
let a = await nd(e, n, { keysDir: t });
|
|
8977
8985
|
r.push({
|
|
8978
8986
|
ok: a.ok,
|
|
8979
8987
|
error: a.error,
|
|
@@ -8983,13 +8991,13 @@ async function ud(e, t) {
|
|
|
8983
8991
|
}
|
|
8984
8992
|
return r;
|
|
8985
8993
|
}
|
|
8986
|
-
async function
|
|
8994
|
+
async function pd(e) {
|
|
8987
8995
|
let t = e?.intervalS ?? 120, n = Ot(e?.dbPath), r = e?.keysDir, i = e?.signal, a = e?.onPhaseChange;
|
|
8988
8996
|
a?.("starting");
|
|
8989
8997
|
let o = Nt(n), s = null;
|
|
8990
8998
|
try {
|
|
8991
8999
|
let [t] = Jn(o, { keysDir: r });
|
|
8992
|
-
|
|
9000
|
+
Bu() && e?.port && (s = Vu(t, e.port));
|
|
8993
9001
|
} finally {
|
|
8994
9002
|
o.close();
|
|
8995
9003
|
}
|
|
@@ -8999,7 +9007,7 @@ async function dd(e) {
|
|
|
8999
9007
|
}
|
|
9000
9008
|
return new Promise((e) => {
|
|
9001
9009
|
let o = !1, c = !1, l = () => {
|
|
9002
|
-
o || (o = !0,
|
|
9010
|
+
o || (o = !0, md(n, r).finally(() => {
|
|
9003
9011
|
o = !1, c || (c = !0, a?.("running"));
|
|
9004
9012
|
}));
|
|
9005
9013
|
}, u = setInterval(l, t * 1e3);
|
|
@@ -9016,30 +9024,30 @@ async function dd(e) {
|
|
|
9016
9024
|
}
|
|
9017
9025
|
});
|
|
9018
9026
|
}
|
|
9019
|
-
async function
|
|
9027
|
+
async function md(e, t) {
|
|
9020
9028
|
let n = Nt(e);
|
|
9021
9029
|
try {
|
|
9022
|
-
await
|
|
9030
|
+
await fd(n, t), ud(n);
|
|
9023
9031
|
} catch (e) {
|
|
9024
|
-
|
|
9032
|
+
dd(n, e instanceof Error ? e.message : String(e), e instanceof Error ? e.stack ?? "" : "");
|
|
9025
9033
|
} finally {
|
|
9026
9034
|
n.close();
|
|
9027
9035
|
}
|
|
9028
9036
|
}
|
|
9029
9037
|
//#endregion
|
|
9030
9038
|
//#region src/test-schema.generated.ts
|
|
9031
|
-
var pd = "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`);", md = "\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";
|
|
9032
|
-
function
|
|
9033
|
-
e.exec(
|
|
9039
|
+
var hd = "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`);", gd = "\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";
|
|
9040
|
+
function _d(e) {
|
|
9041
|
+
e.exec(hd), e.exec(gd), e.pragma("user_version = 6");
|
|
9034
9042
|
}
|
|
9035
|
-
function
|
|
9043
|
+
function vd(e) {
|
|
9036
9044
|
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");
|
|
9037
9045
|
return Number(n.lastInsertRowid);
|
|
9038
9046
|
}
|
|
9039
9047
|
//#endregion
|
|
9040
9048
|
//#region src/index.ts
|
|
9041
|
-
var
|
|
9049
|
+
var yd = "0.20.6";
|
|
9042
9050
|
//#endregion
|
|
9043
|
-
export { ge as Api, $e as CODEMEM_CONFIG_ENV_OVERRIDES, R as CoordinatorStore, Be as DEFAULT_COORDINATOR_DB_PATH, Dt as DEFAULT_DB_PATH,
|
|
9051
|
+
export { ge as Api, $e as CODEMEM_CONFIG_ENV_OVERRIDES, R as CoordinatorStore, Be as DEFAULT_COORDINATOR_DB_PATH, Dt as DEFAULT_DB_PATH, Ou as DEFAULT_SERVICE_TYPE, fi as DEFAULT_TIME_WINDOW_S, Ua as LOW_SIGNAL_TOOLS, ve as MAPPABLE_CLAUDE_HOOK_EVENTS, Tt as MIN_COMPATIBLE_SCHEMA, Du as MemoryStore, bs as ObserverAuthAdapter, Is as ObserverAuthError, ec as ObserverClient, Fl as RawEventSweeper, wt as SCHEMA_VERSION, di as SIGNATURE_VERSION, ho as TRIVIAL_REQUESTS, yd as VERSION, Zi as _resetEmbeddingClient, ji as addressDedupeKey, Vu as advertiseMdns, pu as applyReplicationOps, Lt as assertSchemaReady, uu as backfillReplicationOps, xn as backfillTagsText, Vo as backfillVectors, to as budgetToolEvents, _i as buildAuthHeaders, En as buildBaseUrl, pi as buildCanonicalRequest, hs as buildCodexHeaders, Oa as buildFilterClauses, ka as buildFilterClausesWithContext, ca as buildImportKey, Fe as buildIngestPayloadFromHook, wl as buildMemoryPack, Tl as buildMemoryPackAsync, mo as buildObserverPrompt, Pe as buildRawEventEnvelopeFromHook, Al as buildSessionContext, bo as buildTranscript, Bl as chunkOpsBySize, Yi as chunkText, Xo as cleanOrphanSessions, yi as cleanupNonces, Gl as clockTuple, Nt as connect, Je as connectCoordinator, sd as consecutiveConnectivityFailures, Qn as coordinatorCreateInviteAction, Hi as coordinatorEnabled, $n as coordinatorImportInviteAction, er as coordinatorListJoinRequestsAction, tr as coordinatorReviewJoinRequestAction, Ki as coordinatorStatusSnapshot, Oi as createCoordinatorApp, Ku as cursorAdvances, Tn as deactivateLowSignalMemories, wn as deactivateLowSignalObservations, Le as decodeInvitePayload, zc as dedupeOrderedIds, yo as deriveRequest, zo as deriveTags, Hu as discoverPeersViaMdns, $i as embedTexts, Ie as encodeInvitePayload, Jn as ensureDeviceIdentity, Jc as estimateTokens, Ja as eventToToolEvent, pc as expandQuery, Uc as explain, ma as exportMemories, Xa as extractAdapterEvent, xo as extractAssistantMessages, So as extractAssistantUsage, ze as extractInvitePayload, us as extractOAuthAccess, ps as extractOAuthAccountId, ms as extractOAuthExpires, Co as extractPrompts, ds as extractProviderApiKey, Wl as extractReplicationOps, Ya as extractToolEvents, Ro as fileTags, su as filterReplicationOpsForSync, ou as filterReplicationOpsForSyncWithStatus, Mn as fingerprintPublicKey, vo as firstSentence, jl as flushRawEvents, z as fromJson, Vt as fromJsonStrict, Wn as generateKeypair, et as getCodememConfigPath, rt as getCodememEnvOverrides, Qi as getEmbeddingClient, at as getOpenCodeProviderConfig, xt as getProviderApiKey, yt as getProviderBaseUrl, bt as getProviderHeaders, vt as getProviderOptions, pn as getRawEventStatus, mn as getReliabilityMetrics, Vl as getReplicationCursor, It as getSchemaVersion, Fo as hasMeaningfulObservation, Ji as hashText, Sa as importMemories, Jo as ingest, Zo as ingestMain, dn as initDatabase, _d as initTestSchema, vd as insertTestSession, Re as inviteLink, od as isConnectivityError, Ft as isEmbeddingDisabled, Wa as isInternalMemoryTool, Wt as isLowSignalObservation, Kl as isNewerClock, Ia as isSensitiveFieldName, _o as isTrivialRequest, hc as kindBonus, lt as listConfiguredOpenCodeProviders, qi as listCoordinatorJoinRequests, ot as listCustomProviders, ut as listObserverProviderOptions, Fs as loadObserverConfig, Ze as loadOpenCodeConfig, ss as loadOpenCodeOAuthCache, Au as loadPeerAddresses, Bn as loadPrivateKey, Ln as loadPrivateKeyKeychain, zn as loadPublicKey, Xl as loadReplicationOpsSince, Pt as loadSqliteVec, Gi as lookupCoordinatorPeers, Me as mapClaudeHookPayload, Uu as mdnsAddressesForPeer, Bu as mdnsEnabled, Mi as mergeAddresses, la as mergeSummaryMetadata, Mt as migrateLegacyDbPath, lu as migrateLegacyImportKeys, wo as normalizeAdapterEvents, Ai as normalizeAddress, Ut as normalizeObservation, Ce as normalizeProjectLabel, go as normalizeRequestText, Lo as normalizeTag, Ga as normalizeToolName, Po as parseObserverResponse, ts as parsePositiveMemoryId, es as parseStrictInteger, cd as peerBackoffSeconds, fs as probeAvailableCredentials, Za as projectAdapterToolEvent, Gt as projectBasename, qt as projectClause, Kt as projectColumnClause, Jt as projectMatchesFilter, hn as rawEventsGate, _s as readAuthFile, tt as readCodememConfigFile, Vi as readCoordinatorSyncConfig, ha as readImportPayload, mc as recencyScore, vi as recordNonce, Nu as recordPeerSuccess, ql as recordReplicationOp, Mu as recordSyncAttempt, is as redactText, Wi as registerCoordinatorPresence, ws as renderObserverHeaders, Dn as requestJson, Pc as rerankResults, ft as resolveBuiltInProviderDefaultModel, dt as resolveBuiltInProviderFromModel, pt as resolveBuiltInProviderModel, St as resolveCustomProviderDefaultModel, mt as resolveCustomProviderFromModel, Ct as resolveCustomProviderModel, Ot as resolveDbPath, Ee as resolveHookProject, Rn as resolveKeyPaths, cs as resolveOAuthProvider, ht as resolvePlaceholder, Xt as resolveProject, gn as retryRawEventFailures, gs as runAuthCommand, pd as runSyncDaemon, nd as runSyncPass, za as sanitizePayload, Ha as sanitizeToolOutput, H as schema, Fc as search, ku as selectDialAddresses, Ho as semanticSearch, ta as serializeFloat32, Fu as setPeerLocalActorClaim, Pu as setPeerProjectFilter, Hl as setReplicationCursor, dd as setSyncDaemonError, ud as setSyncDaemonOk, ld as shouldSkipOfflinePeer, mi as signRequest, In as storePrivateKeyKeychain, Bo as storeVectors, Ye as stripJsonComments, Na as stripPrivate, La as stripPrivateObj, Xe as stripTrailingCommas, fd as syncDaemonTick, td as syncOnce, ed as syncPassPreflight, Rt as tableExists, Lc as timeline, B as toJson, V as toJsonNullable, ju as updatePeerAddresses, fn as vacuumDatabase, qn as validateExistingKeypair, hi as verifySignature, nt as writeCodememConfigFile };
|
|
9044
9052
|
|
|
9045
9053
|
//# sourceMappingURL=index.js.map
|