@codemem/core 0.50.0-beta.1 → 0.50.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/coordinator-actions.d.ts +2 -0
- package/dist/coordinator-actions.d.ts.map +1 -1
- package/dist/coordinator-device-removal-list.d.ts +3 -1
- package/dist/coordinator-device-removal-list.d.ts.map +1 -1
- package/dist/{coordinator-runtime-ynLTJI6d.js → coordinator-runtime-ChgCIqfx.js} +400 -396
- package/dist/coordinator-runtime-ChgCIqfx.js.map +1 -0
- package/dist/device-identity-inventory.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10146 -9920
- package/dist/index.js.map +1 -1
- package/dist/ingest-events.d.ts.map +1 -1
- package/dist/internal/cloudflare-coordinator.js +2 -2
- package/dist/internal/relay-runtime.js +10 -10
- package/dist/legacy-team-setup-completion-manifest.d.ts +41 -0
- package/dist/legacy-team-setup-completion-manifest.d.ts.map +1 -1
- package/dist/legacy-team-setup-errors.d.ts +1 -1
- package/dist/legacy-team-setup-errors.d.ts.map +1 -1
- package/dist/{owner-enrollment-start-D8QzF1Ar.js → owner-enrollment-start-CD7R8wy3.js} +2 -2
- package/dist/{owner-enrollment-start-D8QzF1Ar.js.map → owner-enrollment-start-CD7R8wy3.js.map} +1 -1
- package/dist/pairing-removal.d.ts +2 -1
- package/dist/pairing-removal.d.ts.map +1 -1
- package/dist/pi-hooks.d.ts +1 -5
- package/dist/pi-hooks.d.ts.map +1 -1
- package/dist/project-scope-settings.d.ts +14 -1
- package/dist/project-scope-settings.d.ts.map +1 -1
- package/dist/raw-event-flush.d.ts.map +1 -1
- package/dist/{relay-peer-client-w7WdS1AP.js → relay-peer-client-CrFrhN_q.js} +1953 -1949
- package/dist/relay-peer-client-CrFrhN_q.js.map +1 -0
- package/dist/removed-device-local-ids.d.ts +16 -0
- package/dist/removed-device-local-ids.d.ts.map +1 -0
- package/dist/scope-membership-cache-read.d.ts +28 -1
- package/dist/scope-membership-cache-read.d.ts.map +1 -1
- package/dist/scope-membership-cache-test-fixtures.d.ts +1 -0
- package/dist/scope-membership-cache-test-fixtures.d.ts.map +1 -1
- package/dist/scope-membership-cache.d.ts +1 -1
- package/dist/scope-membership-cache.d.ts.map +1 -1
- package/dist/scope-membership-evidence.d.ts +17 -1
- package/dist/scope-membership-evidence.d.ts.map +1 -1
- package/dist/{scope-resolution-B7FK15hx.js → scope-resolution-DXzf4k16.js} +1353 -1313
- package/dist/{scope-resolution-B7FK15hx.js.map → scope-resolution-DXzf4k16.js.map} +1 -1
- package/dist/semantic-worker-entry.js +1 -1
- package/dist/{semantic-worker-job-BjujlM4-.js → semantic-worker-job-DjfAtX64.js} +3 -3
- package/dist/{semantic-worker-job-BjujlM4-.js.map → semantic-worker-job-DjfAtX64.js.map} +1 -1
- package/dist/{semantic-worker-ranking-WaUCapnY.js → semantic-worker-ranking-CZCemeb4.js} +26 -26
- package/dist/{semantic-worker-ranking-WaUCapnY.js.map → semantic-worker-ranking-CZCemeb4.js.map} +1 -1
- package/dist/{sync-auth-constants-DNUSV-Tn.js → sync-auth-constants-CifCg69d.js} +16 -14
- package/dist/{sync-auth-constants-DNUSV-Tn.js.map → sync-auth-constants-CifCg69d.js.map} +1 -1
- package/dist/sync-channel-pass.d.ts.map +1 -1
- package/dist/sync-pass.d.ts +2 -0
- package/dist/sync-pass.d.ts.map +1 -1
- package/dist/sync-reachability-pass-BFTEIkZH.js +2 -0
- package/dist/{sync-reachability-pass-DKEORTbs.js → sync-reachability-pass-vOvswNNG.js} +2738 -2591
- package/dist/sync-reachability-pass-vOvswNNG.js.map +1 -0
- package/dist/sync-replication.d.ts +5 -0
- package/dist/sync-replication.d.ts.map +1 -1
- package/dist/sync-status-test-fixtures.d.ts +1 -1
- package/dist/sync-status-test-fixtures.d.ts.map +1 -1
- package/dist/test-utils.d.ts +4 -1
- package/dist/test-utils.d.ts.map +1 -1
- package/dist/{validated-vector-index-audit-BtUovYuM.js → validated-vector-index-audit-CFSIbYIn.js} +33 -33
- package/dist/{validated-vector-index-audit-BtUovYuM.js.map → validated-vector-index-audit-CFSIbYIn.js.map} +1 -1
- package/dist/viewer-device-removal-commit.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/coordinator-runtime-ynLTJI6d.js.map +0 -1
- package/dist/relay-peer-client-w7WdS1AP.js.map +0 -1
- package/dist/sync-reachability-pass-BpTtRqcV.js +0 -2
- package/dist/sync-reachability-pass-DKEORTbs.js.map +0 -1
|
@@ -3,30 +3,30 @@ import { t as te } from "./relay-ed25519-BNMhPehl.js";
|
|
|
3
3
|
import { createHash as d, randomUUID as f } from "node:crypto";
|
|
4
4
|
import { closeSync as ne, copyFileSync as re, existsSync as p, fchmodSync as ie, fchownSync as ae, fsyncSync as oe, ftruncateSync as se, lstatSync as ce, mkdirSync as le, openSync as ue, readFileSync as m, readlinkSync as de, realpathSync as fe, renameSync as pe, statSync as me, unlinkSync as he, writeSync as ge } from "node:fs";
|
|
5
5
|
import { basename as _e, dirname as h, isAbsolute as ve, join as g, resolve as _ } from "node:path";
|
|
6
|
-
import { homedir as
|
|
7
|
-
import { execFileSync as
|
|
8
|
-
import
|
|
9
|
-
import * as
|
|
10
|
-
import { sql as
|
|
11
|
-
import { index as
|
|
6
|
+
import { homedir as ye } from "node:os";
|
|
7
|
+
import { execFileSync as be } from "node:child_process";
|
|
8
|
+
import xe from "better-sqlite3";
|
|
9
|
+
import * as Se from "sqlite-vec";
|
|
10
|
+
import { sql as v } from "drizzle-orm";
|
|
11
|
+
import { index as y, integer as b, primaryKey as x, real as Ce, sqliteTable as S, text as C, uniqueIndex as w } from "drizzle-orm/sqlite-core";
|
|
12
12
|
//#region \0rolldown/runtime.js
|
|
13
|
-
var
|
|
13
|
+
var we = Object.defineProperty, Te = (e, t) => {
|
|
14
14
|
let n = {};
|
|
15
|
-
for (var r in e)
|
|
15
|
+
for (var r in e) we(n, r, {
|
|
16
16
|
get: e[r],
|
|
17
17
|
enumerable: !0
|
|
18
18
|
});
|
|
19
|
-
return t ||
|
|
19
|
+
return t || we(n, Symbol.toStringTag, { value: "Module" }), n;
|
|
20
20
|
};
|
|
21
21
|
//#endregion
|
|
22
22
|
//#region src/memory-local-capture.ts
|
|
23
|
-
function
|
|
24
|
-
if (
|
|
23
|
+
function Ee(e, t, n) {
|
|
24
|
+
if (T(e, "actors") && e.prepare("SELECT 1 FROM actors WHERE actor_id IN (?, ?, ?)\n AND (is_local <> 1 OR status <> 'active' OR merged_into_actor_id IS NOT NULL) LIMIT 1").get("local:local", `local:${t}`, n ?? `local:${t}`)) throw Error("device_adoption_actor_conflict");
|
|
25
25
|
}
|
|
26
|
-
function
|
|
26
|
+
function T(e, t) {
|
|
27
27
|
return e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(t) !== void 0;
|
|
28
28
|
}
|
|
29
|
-
function
|
|
29
|
+
function De(e) {
|
|
30
30
|
e.exec("CREATE TABLE IF NOT EXISTS memory_local_capture (\n id INTEGER PRIMARY KEY CHECK (id = 1),\n capture_id TEXT NOT NULL UNIQUE,\n created_at TEXT NOT NULL\n );\n CREATE TABLE IF NOT EXISTS memory_local_capture_adoption (\n capture_id TEXT PRIMARY KEY NOT NULL REFERENCES memory_local_capture(capture_id),\n device_id TEXT NOT NULL,\n public_key TEXT NOT NULL,\n fingerprint TEXT NOT NULL,\n created_at TEXT NOT NULL\n );");
|
|
31
31
|
for (let t of ["memory_local_capture", "memory_local_capture_adoption"]) e.exec(`CREATE TRIGGER IF NOT EXISTS ${t}_no_update
|
|
32
32
|
BEFORE UPDATE ON ${t}
|
|
@@ -39,77 +39,77 @@ function Ee(e) {
|
|
|
39
39
|
WHEN EXISTS (SELECT 1 FROM ${t})
|
|
40
40
|
BEGIN SELECT RAISE(ABORT, 'memory_local_capture_immutable'); END;`);
|
|
41
41
|
}
|
|
42
|
-
function
|
|
43
|
-
return
|
|
42
|
+
function Oe(e) {
|
|
43
|
+
return T(e, "memory_local_capture") ? e.prepare("SELECT capture_id FROM memory_local_capture WHERE id = 1").get() ?? null : null;
|
|
44
44
|
}
|
|
45
|
-
function
|
|
46
|
-
let t =
|
|
47
|
-
return !t || !
|
|
45
|
+
function ke(e) {
|
|
46
|
+
let t = Oe(e);
|
|
47
|
+
return !t || !T(e, "memory_local_capture_adoption") ? !1 : !e.prepare("SELECT 1 FROM memory_local_capture_adoption WHERE capture_id = ?").get(t.capture_id);
|
|
48
48
|
}
|
|
49
|
-
function
|
|
50
|
-
if (!
|
|
49
|
+
function Ae(e) {
|
|
50
|
+
if (!T(e, "sync_device")) return null;
|
|
51
51
|
let t = e.prepare("SELECT device_id, public_key, fingerprint FROM sync_device LIMIT 2").all();
|
|
52
52
|
return t.length === 1 ? t[0] ?? null : null;
|
|
53
53
|
}
|
|
54
|
-
function
|
|
54
|
+
function je(e) {
|
|
55
55
|
let [t, n] = e.trim().split(/\s+/u);
|
|
56
56
|
return t === "ssh-ed25519" && n ? `${t} ${n}` : null;
|
|
57
57
|
}
|
|
58
|
-
function
|
|
59
|
-
let r =
|
|
60
|
-
return e.device_id === t && r !== null && n !== void 0 &&
|
|
58
|
+
function Me(e, t, n) {
|
|
59
|
+
let r = je(e.public_key);
|
|
60
|
+
return e.device_id === t && r !== null && n !== void 0 && je(n) === r && i(e.public_key) === e.fingerprint;
|
|
61
61
|
}
|
|
62
|
-
function
|
|
62
|
+
function Ne(e) {
|
|
63
63
|
if (!e.inTransaction) throw Error("memory_source_transaction_required");
|
|
64
|
-
let t =
|
|
64
|
+
let t = Oe(e);
|
|
65
65
|
if (t) return t.capture_id;
|
|
66
|
-
|
|
66
|
+
De(e);
|
|
67
67
|
let n = `local-capture-v1:${f()}`;
|
|
68
68
|
return e.prepare("INSERT INTO memory_local_capture(id, capture_id, created_at) VALUES (1, ?, ?)").run(n, (/* @__PURE__ */ new Date()).toISOString()), n;
|
|
69
69
|
}
|
|
70
|
-
function
|
|
70
|
+
function Pe(e, t, n) {
|
|
71
71
|
if (!e.inTransaction) throw Error("memory_source_transaction_required");
|
|
72
|
-
let r =
|
|
72
|
+
let r = Oe(e);
|
|
73
73
|
if (!r || n.runtimeDeviceId && n.runtimeDeviceId !== "local" && n.runtimeDeviceId !== t) return;
|
|
74
|
-
let i =
|
|
75
|
-
if (!i || !
|
|
74
|
+
let i = Ae(e), a = n.expectedPublicKey ?? n.loadExpectedPublicKey?.();
|
|
75
|
+
if (!i || !Me(i, t, a)) return;
|
|
76
76
|
let o = e.prepare("SELECT device_id, public_key, fingerprint FROM memory_local_capture_adoption WHERE capture_id = ?").get(r.capture_id);
|
|
77
77
|
if (o) {
|
|
78
78
|
if (o.device_id !== i.device_id || o.public_key !== i.public_key || o.fingerprint !== i.fingerprint) throw Error("memory_local_capture_adoption_conflict");
|
|
79
79
|
return;
|
|
80
80
|
}
|
|
81
|
-
|
|
81
|
+
Ee(e, t, n.actorId), e.prepare("INSERT INTO memory_local_capture_adoption(capture_id, device_id, public_key, fingerprint, created_at)\n VALUES (?, ?, ?, ?, ?)").run(r.capture_id, i.device_id, i.public_key, i.fingerprint, (/* @__PURE__ */ new Date()).toISOString());
|
|
82
82
|
}
|
|
83
|
-
function
|
|
84
|
-
if (!
|
|
85
|
-
let r =
|
|
83
|
+
function Fe(e, t, n = {}) {
|
|
84
|
+
if (!T(e, "memory_source_bindings") || !e.prepare("SELECT 1 FROM memory_source_bindings WHERE evidence = 'local_creation' LIMIT 1").get()) return [];
|
|
85
|
+
let r = Oe(e), i = Ae(e);
|
|
86
86
|
if (!i) {
|
|
87
|
-
let n = !
|
|
87
|
+
let n = !T(e, "sync_device") || !e.prepare("SELECT 1 FROM sync_device LIMIT 1").get(), i = T(e, "memory_local_capture_adoption") && e.prepare("SELECT 1 FROM memory_local_capture_adoption LIMIT 1").get();
|
|
88
88
|
return n && !i && t === "local" && r ? [r.capture_id] : [];
|
|
89
89
|
}
|
|
90
|
-
if (i.device_id !== t || !
|
|
90
|
+
if (i.device_id !== t || !Me(i, t, n.expectedPublicKey ?? n.loadExpectedPublicKey?.())) return [];
|
|
91
91
|
let a = [t];
|
|
92
|
-
if (!r || !
|
|
92
|
+
if (!r || !T(e, "memory_local_capture_adoption")) return a;
|
|
93
93
|
let o = e.prepare("SELECT device_id, public_key, fingerprint FROM memory_local_capture_adoption WHERE capture_id = ?").get(r.capture_id);
|
|
94
94
|
return o && o.device_id === i.device_id && o.public_key === i.public_key && o.fingerprint === i.fingerprint && a.push(r.capture_id), a;
|
|
95
95
|
}
|
|
96
96
|
//#endregion
|
|
97
97
|
//#region src/memory-source-identity.ts
|
|
98
|
-
var
|
|
99
|
-
function
|
|
98
|
+
var Ie = "memory-source-v1:", Le = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u;
|
|
99
|
+
function Re(e) {
|
|
100
100
|
e.exec("CREATE TABLE IF NOT EXISTS memory_source_bindings (\n entity_id TEXT PRIMARY KEY,\n source_device_id TEXT NOT NULL,\n evidence TEXT NOT NULL CHECK(evidence IN ('local_creation', 'authenticated_namespace')),\n created_at TEXT NOT NULL\n );\n CREATE TRIGGER IF NOT EXISTS memory_source_bindings_no_update\n BEFORE UPDATE ON memory_source_bindings\n BEGIN SELECT RAISE(ABORT, 'memory_source_binding_immutable'); END;\n CREATE TRIGGER IF NOT EXISTS memory_source_bindings_no_delete\n BEFORE DELETE ON memory_source_bindings\n BEGIN SELECT RAISE(ABORT, 'memory_source_binding_immutable'); END;\n CREATE TRIGGER IF NOT EXISTS memory_source_bindings_no_replace\n BEFORE INSERT ON memory_source_bindings\n WHEN EXISTS (SELECT 1 FROM memory_source_bindings WHERE entity_id = NEW.entity_id)\n BEGIN SELECT RAISE(ABORT, 'memory_source_binding_immutable'); END;");
|
|
101
101
|
}
|
|
102
|
-
function
|
|
102
|
+
function ze(e) {
|
|
103
103
|
return typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e && !/[\p{Cc}\p{Cf}\p{Cs}]/u.test(e);
|
|
104
104
|
}
|
|
105
|
-
function
|
|
106
|
-
if (typeof e != "string" || e.length > 1500 || !e.startsWith(
|
|
105
|
+
function Be(e) {
|
|
106
|
+
if (typeof e != "string" || e.length > 1500 || !e.startsWith(Ie)) return null;
|
|
107
107
|
let [t, n, r] = e.slice(17).split(":");
|
|
108
|
-
if (!t || !n || r !== void 0 || !
|
|
108
|
+
if (!t || !n || r !== void 0 || !Le.test(n)) return null;
|
|
109
109
|
let i = Buffer.from(t, "base64url").toString("utf8");
|
|
110
|
-
return !
|
|
110
|
+
return !ze(i) || Buffer.from(i).toString("base64url") !== t ? null : i;
|
|
111
111
|
}
|
|
112
|
-
function
|
|
112
|
+
function Ve(e, t) {
|
|
113
113
|
let n = e.prepare("SELECT source_device_id, evidence FROM memory_source_bindings WHERE entity_id = ?").get(t);
|
|
114
114
|
return n ? {
|
|
115
115
|
entityId: t,
|
|
@@ -117,34 +117,34 @@ function ze(e, t) {
|
|
|
117
117
|
evidence: n.evidence
|
|
118
118
|
} : null;
|
|
119
119
|
}
|
|
120
|
-
function
|
|
120
|
+
function He(e, t) {
|
|
121
121
|
if (!e.inTransaction) throw Error("memory_source_transaction_required");
|
|
122
|
-
let n =
|
|
122
|
+
let n = Ve(e, t.entityId);
|
|
123
123
|
if (n) {
|
|
124
124
|
if (n.sourceDeviceId !== t.sourceDeviceId) throw Error("memory_source_binding_conflict");
|
|
125
125
|
return n;
|
|
126
126
|
}
|
|
127
127
|
return e.prepare("INSERT INTO memory_source_bindings(entity_id, source_device_id, evidence, created_at)\n VALUES (?, ?, ?, ?)").run(t.entityId, t.sourceDeviceId, t.evidence, (/* @__PURE__ */ new Date()).toISOString()), t;
|
|
128
128
|
}
|
|
129
|
-
function
|
|
129
|
+
function Ue(e) {
|
|
130
130
|
let t = e.prepare("SELECT device_id FROM sync_device").all(), n = t[0]?.device_id;
|
|
131
|
-
if (t.length !== 1 || !n || !
|
|
132
|
-
return
|
|
133
|
-
entityId: `${
|
|
131
|
+
if (t.length !== 1 || !n || !ze(n)) throw Error("memory_source_local_device_required");
|
|
132
|
+
return He(e, {
|
|
133
|
+
entityId: `${Ie}${Buffer.from(n).toString("base64url")}:${f()}`,
|
|
134
134
|
sourceDeviceId: n,
|
|
135
135
|
evidence: "local_creation"
|
|
136
136
|
});
|
|
137
137
|
}
|
|
138
|
-
function
|
|
138
|
+
function We(e, t, n = {}) {
|
|
139
139
|
if (!e.inTransaction) throw Error("memory_source_transaction_required");
|
|
140
140
|
let r = [];
|
|
141
141
|
if (e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'sync_device'").get() && (r = e.prepare("SELECT device_id, public_key, fingerprint FROM sync_device LIMIT 2").all()), r.length > 0) {
|
|
142
142
|
let i = r[0];
|
|
143
|
-
return r.length !== 1 || !i || i.device_id !== t || !
|
|
143
|
+
return r.length !== 1 || !i || i.device_id !== t || !ze(t) || !Me(i, t, n.expectedPublicKey ?? n.loadExpectedPublicKey?.()) ? null : Ue(e);
|
|
144
144
|
}
|
|
145
145
|
if (t !== "local") return null;
|
|
146
|
-
let i =
|
|
147
|
-
return
|
|
146
|
+
let i = Ne(e);
|
|
147
|
+
return He(e, {
|
|
148
148
|
entityId: `memory-local-capture-v1:${Buffer.from(i).toString("base64url")}:${f()}`,
|
|
149
149
|
sourceDeviceId: i,
|
|
150
150
|
evidence: "local_creation"
|
|
@@ -152,12 +152,12 @@ function He(e, t, n = {}) {
|
|
|
152
152
|
}
|
|
153
153
|
//#endregion
|
|
154
154
|
//#region src/home.ts
|
|
155
|
-
function
|
|
156
|
-
return process.env.HOME?.trim() ||
|
|
155
|
+
function E() {
|
|
156
|
+
return process.env.HOME?.trim() || ye();
|
|
157
157
|
}
|
|
158
158
|
//#endregion
|
|
159
159
|
//#region src/observer-config.ts
|
|
160
|
-
function
|
|
160
|
+
function Ge(e) {
|
|
161
161
|
let t = [], n = !1, r = !1;
|
|
162
162
|
for (let i = 0; i < e.length; i++) {
|
|
163
163
|
let a = e.charAt(i);
|
|
@@ -198,7 +198,7 @@ function Ue(e) {
|
|
|
198
198
|
}
|
|
199
199
|
return t.join("");
|
|
200
200
|
}
|
|
201
|
-
function
|
|
201
|
+
function Ke(e) {
|
|
202
202
|
let t = [], n = !1, r = !1;
|
|
203
203
|
for (let i = 0; i < e.length; i++) {
|
|
204
204
|
let a = e.charAt(i);
|
|
@@ -223,8 +223,8 @@ function We(e) {
|
|
|
223
223
|
}
|
|
224
224
|
return t.join("");
|
|
225
225
|
}
|
|
226
|
-
function
|
|
227
|
-
let e = g(
|
|
226
|
+
function qe() {
|
|
227
|
+
let e = g(E(), ".config", "opencode"), t = [g(e, "opencode.json"), g(e, "opencode.jsonc")].find((e) => p(e));
|
|
228
228
|
if (!t) return {};
|
|
229
229
|
let n;
|
|
230
230
|
try {
|
|
@@ -236,43 +236,43 @@ function Ge() {
|
|
|
236
236
|
return JSON.parse(n);
|
|
237
237
|
} catch {}
|
|
238
238
|
try {
|
|
239
|
-
let e =
|
|
239
|
+
let e = Ke(Ge(n));
|
|
240
240
|
return JSON.parse(e);
|
|
241
241
|
} catch {
|
|
242
242
|
return {};
|
|
243
243
|
}
|
|
244
244
|
}
|
|
245
|
-
function
|
|
246
|
-
return e.startsWith("~/") ? g(
|
|
245
|
+
function D(e) {
|
|
246
|
+
return e.startsWith("~/") ? g(E(), e.slice(2)) : e;
|
|
247
247
|
}
|
|
248
|
-
function
|
|
248
|
+
function Je(e) {
|
|
249
249
|
return /^[A-Za-z0-9._:-]+$/.test(e) && !/^\.+$/.test(e);
|
|
250
250
|
}
|
|
251
|
-
function
|
|
251
|
+
function O(e) {
|
|
252
252
|
let t = e.trim();
|
|
253
|
-
if (!t || !
|
|
254
|
-
return g(
|
|
253
|
+
if (!t || !Je(t)) throw Error(`Invalid workspace id for config path: ${e}`);
|
|
254
|
+
return g(E(), ".codemem", "workspaces", t, "config", "codemem.json");
|
|
255
255
|
}
|
|
256
|
-
function
|
|
256
|
+
function Ye() {
|
|
257
257
|
let e = process.env.CODEMEM_RUNTIME_ROOT?.trim();
|
|
258
258
|
if (e) {
|
|
259
|
-
let t =
|
|
259
|
+
let t = D(e);
|
|
260
260
|
if (ve(t)) return g(t, "config", "codemem.json");
|
|
261
261
|
}
|
|
262
262
|
let t = process.env.CODEMEM_WORKSPACE_ID?.trim();
|
|
263
|
-
return !t || !
|
|
263
|
+
return !t || !Je(t) ? null : O(t);
|
|
264
264
|
}
|
|
265
|
-
function
|
|
266
|
-
let e = g(
|
|
265
|
+
function Xe() {
|
|
266
|
+
let e = g(E(), ".config", "codemem");
|
|
267
267
|
return [g(e, "config.json"), g(e, "config.jsonc")].find((e) => p(e)) ?? g(e, "config.json");
|
|
268
268
|
}
|
|
269
|
-
function
|
|
270
|
-
return
|
|
269
|
+
function Ze() {
|
|
270
|
+
return tt(void 0, "write").resolved.path;
|
|
271
271
|
}
|
|
272
|
-
function
|
|
273
|
-
return
|
|
272
|
+
function Qe(e) {
|
|
273
|
+
return it(O(e));
|
|
274
274
|
}
|
|
275
|
-
var
|
|
275
|
+
var $e = {
|
|
276
276
|
actor_id: "CODEMEM_ACTOR_ID",
|
|
277
277
|
actor_display_name: "CODEMEM_ACTOR_DISPLAY_NAME",
|
|
278
278
|
claude_command: "CODEMEM_CLAUDE_COMMAND",
|
|
@@ -336,7 +336,7 @@ var Ze = {
|
|
|
336
336
|
raw_events_retention_enabled: "CODEMEM_RAW_EVENTS_RETENTION_ENABLED",
|
|
337
337
|
raw_events_retention_max_age_days: "CODEMEM_RAW_EVENTS_RETENTION_MAX_AGE_DAYS"
|
|
338
338
|
};
|
|
339
|
-
function
|
|
339
|
+
function et(e) {
|
|
340
340
|
if (e == null) return null;
|
|
341
341
|
if (Array.isArray(e)) {
|
|
342
342
|
let t = e.filter((e) => typeof e == "string" && e.trim() !== "");
|
|
@@ -355,10 +355,10 @@ function Qe(e) {
|
|
|
355
355
|
let n = t.split(/\s+/).filter((e) => e !== "");
|
|
356
356
|
return n.length > 0 ? n : null;
|
|
357
357
|
}
|
|
358
|
-
function
|
|
358
|
+
function tt(e, t = "read") {
|
|
359
359
|
let n = [];
|
|
360
360
|
if (e?.trim()) {
|
|
361
|
-
let t =
|
|
361
|
+
let t = D(e.trim());
|
|
362
362
|
n.push({
|
|
363
363
|
path: t,
|
|
364
364
|
source: "cli-flag",
|
|
@@ -369,7 +369,7 @@ function $e(e, t = "read") {
|
|
|
369
369
|
}
|
|
370
370
|
let r = process.env.CODEMEM_CONFIG?.trim();
|
|
371
371
|
if (r) {
|
|
372
|
-
let e =
|
|
372
|
+
let e = D(r);
|
|
373
373
|
n.push({
|
|
374
374
|
path: e,
|
|
375
375
|
source: "env-codemem-config",
|
|
@@ -380,7 +380,7 @@ function $e(e, t = "read") {
|
|
|
380
380
|
}
|
|
381
381
|
let i = process.env.CODEMEM_RUNTIME_ROOT?.trim();
|
|
382
382
|
if (i) {
|
|
383
|
-
let e =
|
|
383
|
+
let e = D(i), t = ve(e), r = g(e, "config", "codemem.json");
|
|
384
384
|
n.push({
|
|
385
385
|
path: r,
|
|
386
386
|
source: "env-runtime-root",
|
|
@@ -391,7 +391,7 @@ function $e(e, t = "read") {
|
|
|
391
391
|
}
|
|
392
392
|
let a = process.env.CODEMEM_WORKSPACE_ID?.trim();
|
|
393
393
|
if (a) {
|
|
394
|
-
let e =
|
|
394
|
+
let e = Je(a), t = e ? O(a) : g(E(), ".codemem", "workspaces", a, "config", "codemem.json");
|
|
395
395
|
n.push({
|
|
396
396
|
path: t,
|
|
397
397
|
source: "env-workspace-id",
|
|
@@ -400,7 +400,7 @@ function $e(e, t = "read") {
|
|
|
400
400
|
valid: e
|
|
401
401
|
});
|
|
402
402
|
}
|
|
403
|
-
let o =
|
|
403
|
+
let o = Xe();
|
|
404
404
|
n.push({
|
|
405
405
|
path: o,
|
|
406
406
|
source: "legacy-global",
|
|
@@ -428,14 +428,14 @@ function $e(e, t = "read") {
|
|
|
428
428
|
fallbackChain: u
|
|
429
429
|
};
|
|
430
430
|
}
|
|
431
|
-
function
|
|
432
|
-
return
|
|
431
|
+
function nt() {
|
|
432
|
+
return tt(void 0, "read").resolved.path;
|
|
433
433
|
}
|
|
434
|
-
function
|
|
435
|
-
return nt(
|
|
434
|
+
function rt() {
|
|
435
|
+
return it(nt());
|
|
436
436
|
}
|
|
437
|
-
function
|
|
438
|
-
let t =
|
|
437
|
+
function it(e) {
|
|
438
|
+
let t = D(e);
|
|
439
439
|
if (!p(t)) return {};
|
|
440
440
|
let n;
|
|
441
441
|
try {
|
|
@@ -449,50 +449,50 @@ function nt(e) {
|
|
|
449
449
|
return typeof e == "object" && e && !Array.isArray(e) ? e : {};
|
|
450
450
|
} catch {}
|
|
451
451
|
try {
|
|
452
|
-
let e =
|
|
452
|
+
let e = Ke(Ge(n)), t = JSON.parse(e);
|
|
453
453
|
return typeof t == "object" && t && !Array.isArray(t) ? t : {};
|
|
454
454
|
} catch {
|
|
455
455
|
return {};
|
|
456
456
|
}
|
|
457
457
|
}
|
|
458
|
-
var
|
|
458
|
+
var k = class extends Error {
|
|
459
459
|
code;
|
|
460
460
|
constructor(e, t, n) {
|
|
461
461
|
super(t, n), this.name = "CodememConfigMutationError", this.code = e;
|
|
462
462
|
}
|
|
463
|
-
},
|
|
464
|
-
function
|
|
465
|
-
if (
|
|
463
|
+
}, A;
|
|
464
|
+
function at() {
|
|
465
|
+
if (A !== void 0) return A;
|
|
466
466
|
try {
|
|
467
|
-
|
|
467
|
+
be("/bin/cp", ["--version"], { stdio: "ignore" }), A = !0;
|
|
468
468
|
} catch (e) {
|
|
469
|
-
if (e instanceof Error && "code" in e && e.code === "ENOENT" || e instanceof Error && "status" in e && typeof e.status == "number") return
|
|
470
|
-
throw new
|
|
469
|
+
if (e instanceof Error && "code" in e && e.code === "ENOENT" || e instanceof Error && "status" in e && typeof e.status == "number") return A = !1, A;
|
|
470
|
+
throw new k("unreadable", "Cannot update config because extended access metadata support could not be checked.", { cause: e });
|
|
471
471
|
}
|
|
472
|
-
return
|
|
472
|
+
return A;
|
|
473
473
|
}
|
|
474
|
-
function
|
|
475
|
-
|
|
474
|
+
function ot(e) {
|
|
475
|
+
be("/usr/bin/chflags", ["0", "/dev/fd/3"], { stdio: [
|
|
476
476
|
"ignore",
|
|
477
477
|
"pipe",
|
|
478
478
|
"pipe",
|
|
479
479
|
e
|
|
480
480
|
] });
|
|
481
481
|
}
|
|
482
|
-
function
|
|
482
|
+
function st(e, t) {
|
|
483
483
|
let n, r;
|
|
484
484
|
if (process.platform === "darwin" ? (n = [
|
|
485
485
|
"-p",
|
|
486
486
|
e,
|
|
487
487
|
"/dev/fd/3"
|
|
488
|
-
], r = { ...process.env }, delete r.COPYFILE_DISABLE) : process.platform === "linux" &&
|
|
488
|
+
], r = { ...process.env }, delete r.COPYFILE_DISABLE) : process.platform === "linux" && at() && (n = [
|
|
489
489
|
"--preserve=mode,ownership,xattr",
|
|
490
490
|
"--",
|
|
491
491
|
e,
|
|
492
492
|
"/proc/self/fd/3"
|
|
493
493
|
]), !n) return !1;
|
|
494
494
|
try {
|
|
495
|
-
return
|
|
495
|
+
return be("/bin/cp", n, {
|
|
496
496
|
env: r,
|
|
497
497
|
stdio: [
|
|
498
498
|
"ignore",
|
|
@@ -500,15 +500,15 @@ function at(e, t) {
|
|
|
500
500
|
"pipe",
|
|
501
501
|
t
|
|
502
502
|
]
|
|
503
|
-
}), process.platform === "darwin" &&
|
|
503
|
+
}), process.platform === "darwin" && ot(t), !0;
|
|
504
504
|
} catch (n) {
|
|
505
505
|
if (process.platform === "darwin") try {
|
|
506
|
-
|
|
506
|
+
ot(t);
|
|
507
507
|
} catch {}
|
|
508
|
-
throw new
|
|
508
|
+
throw new k("unreadable", `Cannot update config because extended access metadata from ${e} could not be preserved.`, { cause: n });
|
|
509
509
|
}
|
|
510
510
|
}
|
|
511
|
-
var
|
|
511
|
+
var ct = {
|
|
512
512
|
open: ue,
|
|
513
513
|
close: ne,
|
|
514
514
|
chown: ae,
|
|
@@ -518,20 +518,20 @@ var ot = {
|
|
|
518
518
|
write: ge,
|
|
519
519
|
rename: pe,
|
|
520
520
|
unlink: he,
|
|
521
|
-
seedMetadata:
|
|
522
|
-
},
|
|
521
|
+
seedMetadata: st
|
|
522
|
+
}, lt = {
|
|
523
523
|
close: ne,
|
|
524
524
|
unlink: he
|
|
525
525
|
};
|
|
526
|
-
function
|
|
526
|
+
function ut(e) {
|
|
527
527
|
return d("sha256").update(e).digest("hex");
|
|
528
528
|
}
|
|
529
|
-
function
|
|
529
|
+
function dt(e) {
|
|
530
530
|
if (!e.trim()) return {
|
|
531
531
|
status: "invalid",
|
|
532
532
|
reason: "empty"
|
|
533
533
|
};
|
|
534
|
-
for (let t of [e,
|
|
534
|
+
for (let t of [e, Ke(Ge(e))]) try {
|
|
535
535
|
let e = JSON.parse(t);
|
|
536
536
|
return typeof e == "object" && e && !Array.isArray(e) ? {
|
|
537
537
|
status: "valid",
|
|
@@ -546,8 +546,8 @@ function lt(e) {
|
|
|
546
546
|
reason: "parse_error"
|
|
547
547
|
};
|
|
548
548
|
}
|
|
549
|
-
function
|
|
550
|
-
let t = e ?
|
|
549
|
+
function j(e) {
|
|
550
|
+
let t = e ? D(e) : Ze();
|
|
551
551
|
if (!p(t)) return {
|
|
552
552
|
status: "missing",
|
|
553
553
|
path: t,
|
|
@@ -571,35 +571,35 @@ function ut(e) {
|
|
|
571
571
|
path: t
|
|
572
572
|
};
|
|
573
573
|
}
|
|
574
|
-
let i =
|
|
574
|
+
let i = dt(n);
|
|
575
575
|
return i.status === "invalid" ? {
|
|
576
576
|
...i,
|
|
577
577
|
path: t
|
|
578
578
|
} : {
|
|
579
579
|
...i,
|
|
580
580
|
path: t,
|
|
581
|
-
revision:
|
|
581
|
+
revision: ut(n),
|
|
582
582
|
...r
|
|
583
583
|
};
|
|
584
584
|
}
|
|
585
|
-
function
|
|
585
|
+
function ft(e, t) {
|
|
586
586
|
try {
|
|
587
587
|
t(e);
|
|
588
588
|
} catch (e) {
|
|
589
589
|
if ((e instanceof Error && "code" in e ? String(e.code) : "") !== "ENOENT") throw e;
|
|
590
590
|
}
|
|
591
591
|
}
|
|
592
|
-
function
|
|
592
|
+
function pt(e, t, n) {
|
|
593
593
|
try {
|
|
594
|
-
|
|
594
|
+
ft(e, t);
|
|
595
595
|
} catch (e) {
|
|
596
596
|
if (!n) throw e;
|
|
597
597
|
}
|
|
598
598
|
}
|
|
599
|
-
function
|
|
599
|
+
function M(e) {
|
|
600
600
|
let t = /* @__PURE__ */ new Set(), n = e;
|
|
601
601
|
for (;;) {
|
|
602
|
-
if (t.has(n)) throw new
|
|
602
|
+
if (t.has(n)) throw new k("unreadable", `Cannot update config because ${e} contains a symbolic-link cycle.`);
|
|
603
603
|
t.add(n);
|
|
604
604
|
try {
|
|
605
605
|
return fe(n);
|
|
@@ -620,7 +620,7 @@ function N(e) {
|
|
|
620
620
|
}
|
|
621
621
|
}
|
|
622
622
|
}
|
|
623
|
-
function
|
|
623
|
+
function mt(e, t) {
|
|
624
624
|
let n = null;
|
|
625
625
|
try {
|
|
626
626
|
n = t.open(h(e), "r"), t.sync(n);
|
|
@@ -630,7 +630,7 @@ function pt(e, t) {
|
|
|
630
630
|
} catch {}
|
|
631
631
|
}
|
|
632
632
|
}
|
|
633
|
-
function
|
|
633
|
+
function ht(e, t, n) {
|
|
634
634
|
let r = Buffer.from(t, "utf8"), i = 0;
|
|
635
635
|
for (; i < r.length;) {
|
|
636
636
|
let t = n(e, r, i, r.length - i, i);
|
|
@@ -638,39 +638,39 @@ function mt(e, t, n) {
|
|
|
638
638
|
i += t;
|
|
639
639
|
}
|
|
640
640
|
}
|
|
641
|
-
function
|
|
642
|
-
let o = a ?
|
|
641
|
+
function gt(e, t, n, r = ct, i, { followSymlink: a = !0 } = {}) {
|
|
642
|
+
let o = a ? M(e) : e, s = `${o}.tmp-${process.pid}-${f()}`, c = null, l = !1;
|
|
643
643
|
try {
|
|
644
644
|
let e = typeof n == "number" ? n : n?.mode;
|
|
645
645
|
if (c = r.open(s, "wx", e ?? 384), typeof n == "object" && r.seedMetadata?.(o, c) === !0) {
|
|
646
646
|
if (!r.truncate) throw Error("Seeded config replacement requires truncate");
|
|
647
647
|
r.truncate(c, 0);
|
|
648
648
|
}
|
|
649
|
-
typeof n == "object" && process.platform !== "win32" && r.chown?.(c, n.uid, n.gid), e != null && r.chmod(c, e),
|
|
649
|
+
typeof n == "object" && process.platform !== "win32" && r.chown?.(c, n.uid, n.gid), e != null && r.chmod(c, e), ht(c, t, r.write), r.sync(c);
|
|
650
650
|
let a = c;
|
|
651
|
-
c = null, r.close(a), i?.(), r.rename(s, o), l = !0,
|
|
651
|
+
c = null, r.close(a), i?.(), r.rename(s, o), l = !0, mt(o, r);
|
|
652
652
|
} finally {
|
|
653
653
|
try {
|
|
654
654
|
c != null && r.close(c);
|
|
655
655
|
} finally {
|
|
656
|
-
|
|
656
|
+
pt(s, r.unlink, l);
|
|
657
657
|
}
|
|
658
658
|
}
|
|
659
659
|
}
|
|
660
|
-
function
|
|
660
|
+
function _t(e) {
|
|
661
661
|
if (e.status === "missing") return {};
|
|
662
662
|
if (e.status === "valid") return e.data;
|
|
663
|
-
throw e.status === "unreadable" ? new
|
|
663
|
+
throw e.status === "unreadable" ? new k("unreadable", `Cannot update config because ${e.path} could not be read.`) : new k("invalid", `Cannot update config because ${e.path} is not a valid JSON object.`);
|
|
664
664
|
}
|
|
665
|
-
function
|
|
665
|
+
function vt(e) {
|
|
666
666
|
if (!p(e)) return "missing";
|
|
667
667
|
try {
|
|
668
|
-
return
|
|
668
|
+
return ut(m(e, "utf8"));
|
|
669
669
|
} catch {
|
|
670
670
|
return "unreadable";
|
|
671
671
|
}
|
|
672
672
|
}
|
|
673
|
-
function
|
|
673
|
+
function yt(e) {
|
|
674
674
|
if (!p(e)) return "missing";
|
|
675
675
|
try {
|
|
676
676
|
let t = me(e, { bigint: !0 });
|
|
@@ -686,20 +686,20 @@ function vt(e) {
|
|
|
686
686
|
return "unreadable";
|
|
687
687
|
}
|
|
688
688
|
}
|
|
689
|
-
function yt(e, t) {
|
|
690
|
-
return typeof e != "string" && bt(e, t) && e.ctimeNs === t.ctimeNs && e.dev === t.dev && e.ino === t.ino;
|
|
691
|
-
}
|
|
692
689
|
function bt(e, t) {
|
|
690
|
+
return typeof e != "string" && xt(e, t) && e.ctimeNs === t.ctimeNs && e.dev === t.dev && e.ino === t.ino;
|
|
691
|
+
}
|
|
692
|
+
function xt(e, t) {
|
|
693
693
|
return typeof e != "string" && e.mode === t.mode && e.uid === t.uid && e.gid === t.gid;
|
|
694
694
|
}
|
|
695
|
-
function
|
|
695
|
+
function St(e) {
|
|
696
696
|
if (e.status === "valid") return {
|
|
697
697
|
mode: e.mode,
|
|
698
698
|
uid: e.uid,
|
|
699
699
|
gid: e.gid
|
|
700
700
|
};
|
|
701
701
|
}
|
|
702
|
-
function
|
|
702
|
+
function Ct(e) {
|
|
703
703
|
let t = `${e}.lock`;
|
|
704
704
|
try {
|
|
705
705
|
return {
|
|
@@ -707,10 +707,10 @@ function St(e) {
|
|
|
707
707
|
path: t
|
|
708
708
|
};
|
|
709
709
|
} catch (n) {
|
|
710
|
-
throw (n instanceof Error && "code" in n ? String(n.code) : "") === "EEXIST" ? new
|
|
710
|
+
throw (n instanceof Error && "code" in n ? String(n.code) : "") === "EEXIST" ? new k("busy", `Cannot update config because another writer is updating ${e}. Retry the save; if no save is active, remove the stale lock at ${t}.`, { cause: n }) : new k("unreadable", `Cannot update config because its writer lock could not be created at ${t}.`, { cause: n });
|
|
711
711
|
}
|
|
712
712
|
}
|
|
713
|
-
function
|
|
713
|
+
function wt(e, t) {
|
|
714
714
|
let n;
|
|
715
715
|
try {
|
|
716
716
|
t.close(e.fd);
|
|
@@ -718,43 +718,43 @@ function Ct(e, t) {
|
|
|
718
718
|
n = e;
|
|
719
719
|
}
|
|
720
720
|
try {
|
|
721
|
-
|
|
721
|
+
ft(e.path, t.unlink);
|
|
722
722
|
} catch (e) {
|
|
723
723
|
n ??= e;
|
|
724
724
|
}
|
|
725
725
|
if (n !== void 0) throw n;
|
|
726
726
|
}
|
|
727
|
-
function
|
|
727
|
+
function Tt(e, t = lt) {
|
|
728
728
|
let n;
|
|
729
729
|
for (let r of e.reverse()) try {
|
|
730
|
-
|
|
730
|
+
wt(r, t);
|
|
731
731
|
} catch (e) {
|
|
732
732
|
n ??= e;
|
|
733
733
|
}
|
|
734
734
|
if (n !== void 0) throw n;
|
|
735
735
|
}
|
|
736
|
-
function
|
|
736
|
+
function Et(e, t, n) {
|
|
737
737
|
try {
|
|
738
|
-
|
|
738
|
+
Tt(e, n);
|
|
739
739
|
} catch (e) {
|
|
740
740
|
if (!t) throw e;
|
|
741
741
|
}
|
|
742
742
|
}
|
|
743
|
-
function
|
|
743
|
+
function Dt(e) {
|
|
744
744
|
let t = [...new Set(e)].sort((e, t) => e < t ? -1 : +(e > t)), n = [];
|
|
745
745
|
try {
|
|
746
|
-
for (let e of t) le(h(e), { recursive: !0 }), n.push(
|
|
746
|
+
for (let e of t) le(h(e), { recursive: !0 }), n.push(Ct(e));
|
|
747
747
|
return n;
|
|
748
748
|
} catch (e) {
|
|
749
749
|
try {
|
|
750
|
-
|
|
750
|
+
Tt(n);
|
|
751
751
|
} catch {}
|
|
752
752
|
throw e;
|
|
753
753
|
}
|
|
754
754
|
}
|
|
755
|
-
function
|
|
755
|
+
function Ot(e, t, n) {
|
|
756
756
|
for (let r = 0; r < 3; r += 1) {
|
|
757
|
-
let r =
|
|
757
|
+
let r = j(e), i = n.fallbackReadPath ?? (t ? nt() : void 0), a = n.expectedMutationPath ? D(n.expectedMutationPath) : M(e), o = r.status === "missing" && i != null ? M(D(i)) : void 0, s = Dt([a]), c = M(e) === a, l = o === void 0 || M(D(i ?? e)) === o;
|
|
758
758
|
if (c && l) return {
|
|
759
759
|
preliminaryTarget: r,
|
|
760
760
|
fallbackReadPath: i,
|
|
@@ -762,30 +762,30 @@ function Dt(e, t, n) {
|
|
|
762
762
|
fallbackMutationPath: o,
|
|
763
763
|
locks: s
|
|
764
764
|
};
|
|
765
|
-
|
|
765
|
+
Tt(s);
|
|
766
766
|
}
|
|
767
|
-
throw new
|
|
768
|
-
}
|
|
769
|
-
function Ot(e, t, n) {
|
|
770
|
-
if (e.status !== "missing" && t.status === "missing") throw new j("changed", `Cannot update config because ${n} changed before the save. Retry the save.`);
|
|
767
|
+
throw new k("changed", `Cannot update config because ${e} changed before the save. Retry the save.`);
|
|
771
768
|
}
|
|
772
769
|
function kt(e, t, n) {
|
|
770
|
+
if (e.status !== "missing" && t.status === "missing") throw new k("changed", `Cannot update config because ${n} changed before the save. Retry the save.`);
|
|
771
|
+
}
|
|
772
|
+
function At(e, t, n) {
|
|
773
773
|
if (e.status !== "missing") return e;
|
|
774
774
|
let r = n ?? t;
|
|
775
|
-
return r === t ? e :
|
|
776
|
-
}
|
|
777
|
-
function At(e) {
|
|
778
|
-
let t = vt(e.targetMutationPath);
|
|
779
|
-
if (N(e.targetPath) !== e.targetMutationPath || _t(e.targetMutationPath) !== e.expectedRevision || e.expectedMetadata !== void 0 && !bt(t, e.expectedMetadata) || e.expectedIdentity !== void 0 && !yt(t, e.expectedIdentity)) throw new j("changed", `Cannot update config because ${e.targetPath} changed during the save. Retry the save.`);
|
|
780
|
-
if (e.fallbackMutationPath !== void 0 && N(k(e.fallbackReadPath ?? e.targetPath)) !== e.fallbackMutationPath) throw new j("changed", `Cannot update config because ${e.fallbackReadPath} changed during the save. Retry the save.`);
|
|
781
|
-
if (e.inputOutcome.path !== e.targetMutationPath && _t(e.inputOutcome.path) !== e.inputRevision) throw new j("changed", `Cannot update config because ${e.inputOutcome.path} changed during the save. Retry the save.`);
|
|
775
|
+
return r === t ? e : j(r);
|
|
782
776
|
}
|
|
783
|
-
function jt(e
|
|
784
|
-
|
|
777
|
+
function jt(e) {
|
|
778
|
+
let t = yt(e.targetMutationPath);
|
|
779
|
+
if (M(e.targetPath) !== e.targetMutationPath || vt(e.targetMutationPath) !== e.expectedRevision || e.expectedMetadata !== void 0 && !xt(t, e.expectedMetadata) || e.expectedIdentity !== void 0 && !bt(t, e.expectedIdentity)) throw new k("changed", `Cannot update config because ${e.targetPath} changed during the save. Retry the save.`);
|
|
780
|
+
if (e.fallbackMutationPath !== void 0 && M(D(e.fallbackReadPath ?? e.targetPath)) !== e.fallbackMutationPath) throw new k("changed", `Cannot update config because ${e.fallbackReadPath} changed during the save. Retry the save.`);
|
|
781
|
+
if (e.inputOutcome.path !== e.targetMutationPath && vt(e.inputOutcome.path) !== e.inputRevision) throw new k("changed", `Cannot update config because ${e.inputOutcome.path} changed during the save. Retry the save.`);
|
|
785
782
|
}
|
|
786
783
|
function Mt(e, t, n) {
|
|
784
|
+
if (n != null && t !== n) throw new k("changed", `Cannot update config because ${e} changed before the save. Retry the save.`);
|
|
785
|
+
}
|
|
786
|
+
function Nt(e, t, n) {
|
|
787
787
|
let r = e.status === "valid" ? e.revision : "missing";
|
|
788
|
-
return
|
|
788
|
+
return Mt(t, r, n), {
|
|
789
789
|
expectedRevision: r,
|
|
790
790
|
expectedIdentity: e.status === "valid" ? {
|
|
791
791
|
mode: e.mode,
|
|
@@ -797,15 +797,15 @@ function Mt(e, t, n) {
|
|
|
797
797
|
} : void 0
|
|
798
798
|
};
|
|
799
799
|
}
|
|
800
|
-
function
|
|
801
|
-
|
|
800
|
+
function Pt(e) {
|
|
801
|
+
gt(e.targetMutationPath, e.text, e.metadata, ct, () => jt(e));
|
|
802
802
|
}
|
|
803
|
-
function
|
|
804
|
-
let r = t ?
|
|
803
|
+
function Ft(e, t, n = {}) {
|
|
804
|
+
let r = t ? D(t) : Ze(), { preliminaryTarget: i, fallbackReadPath: a, targetMutationPath: o, fallbackMutationPath: s, locks: c } = Ot(r, t == null, n), l = !1;
|
|
805
805
|
try {
|
|
806
|
-
let t =
|
|
807
|
-
|
|
808
|
-
let c =
|
|
806
|
+
let t = j(o);
|
|
807
|
+
kt(i, t, r);
|
|
808
|
+
let c = At(t, o, s ?? a), { expectedRevision: u, expectedIdentity: ee } = Nt(t, r, n.expectedRevision), te = { ..._t(c) }, d = e(te, t);
|
|
809
809
|
if (d === void 0) return {
|
|
810
810
|
path: r,
|
|
811
811
|
mutationPath: o,
|
|
@@ -813,13 +813,13 @@ function Pt(e, t, n = {}) {
|
|
|
813
813
|
revision: u
|
|
814
814
|
};
|
|
815
815
|
let f = c.status === "valid" ? c.revision : c.status, ne = `${JSON.stringify(d, null, 2)}\n`;
|
|
816
|
-
return
|
|
816
|
+
return Pt({
|
|
817
817
|
targetPath: r,
|
|
818
818
|
targetMutationPath: o,
|
|
819
819
|
text: ne,
|
|
820
|
-
metadata:
|
|
820
|
+
metadata: St(t),
|
|
821
821
|
expectedRevision: u,
|
|
822
|
-
expectedMetadata:
|
|
822
|
+
expectedMetadata: St(t),
|
|
823
823
|
expectedIdentity: ee,
|
|
824
824
|
fallbackReadPath: a,
|
|
825
825
|
fallbackMutationPath: s,
|
|
@@ -829,28 +829,28 @@ function Pt(e, t, n = {}) {
|
|
|
829
829
|
path: r,
|
|
830
830
|
mutationPath: o,
|
|
831
831
|
data: d,
|
|
832
|
-
revision:
|
|
832
|
+
revision: ut(ne)
|
|
833
833
|
};
|
|
834
834
|
} finally {
|
|
835
|
-
|
|
835
|
+
Et(c, l, n.lockCleanupOperations ?? lt);
|
|
836
836
|
}
|
|
837
837
|
}
|
|
838
|
-
function
|
|
839
|
-
let i =
|
|
838
|
+
function It(e, t, n, r = lt) {
|
|
839
|
+
let i = D(e), a = n ?? M(i), o = Ct(a), s = !1;
|
|
840
840
|
try {
|
|
841
|
-
if (
|
|
842
|
-
he(a), s = !0,
|
|
841
|
+
if (M(i) !== a || vt(a) !== t) throw new k("changed", `Cannot restore config because ${i} changed after the save.`);
|
|
842
|
+
he(a), s = !0, mt(a, ct);
|
|
843
843
|
} finally {
|
|
844
|
-
|
|
844
|
+
Et([o], s, r);
|
|
845
845
|
}
|
|
846
846
|
}
|
|
847
|
-
function It(e, t) {
|
|
848
|
-
return Pt(() => e, t).path;
|
|
849
|
-
}
|
|
850
847
|
function Lt(e, t) {
|
|
851
|
-
return
|
|
848
|
+
return Ft(() => e, t).path;
|
|
849
|
+
}
|
|
850
|
+
function Rt(e, t) {
|
|
851
|
+
return Lt(t, O(e));
|
|
852
852
|
}
|
|
853
|
-
var
|
|
853
|
+
var zt = /* @__PURE__ */ new Set([
|
|
854
854
|
"observer_provider",
|
|
855
855
|
"observer_model",
|
|
856
856
|
"observer_runtime",
|
|
@@ -866,7 +866,7 @@ var Rt = /* @__PURE__ */ new Set([
|
|
|
866
866
|
"observer_auth_source",
|
|
867
867
|
"observer_auth_file"
|
|
868
868
|
]);
|
|
869
|
-
function
|
|
869
|
+
function Bt(e, t) {
|
|
870
870
|
let n = e === "observer_auth_command";
|
|
871
871
|
if (!t.trim()) return n ? [] : {};
|
|
872
872
|
try {
|
|
@@ -875,8 +875,8 @@ function zt(e, t) {
|
|
|
875
875
|
if (typeof e == "object" && e && !Array.isArray(e)) return e;
|
|
876
876
|
} catch {}
|
|
877
877
|
}
|
|
878
|
-
function
|
|
879
|
-
if (
|
|
878
|
+
function Vt(e, t) {
|
|
879
|
+
if (zt.has(e)) return t;
|
|
880
880
|
switch (e) {
|
|
881
881
|
case "observer_temperature":
|
|
882
882
|
case "observer_simple_temperature":
|
|
@@ -901,86 +901,86 @@ function Bt(e, t) {
|
|
|
901
901
|
"legacy_xml"
|
|
902
902
|
].includes(t) ? t : void 0;
|
|
903
903
|
case "claude_command":
|
|
904
|
-
case "codex_command": return
|
|
904
|
+
case "codex_command": return et(t) ?? void 0;
|
|
905
905
|
case "observer_headers":
|
|
906
|
-
case "observer_auth_command": return
|
|
906
|
+
case "observer_auth_command": return Bt(e, t);
|
|
907
907
|
default: return t === "" ? void 0 : t;
|
|
908
908
|
}
|
|
909
909
|
}
|
|
910
|
-
function
|
|
910
|
+
function Ht() {
|
|
911
911
|
let e = {};
|
|
912
|
-
for (let [t, n] of Object.entries(
|
|
912
|
+
for (let [t, n] of Object.entries($e)) {
|
|
913
913
|
let r = process.env[n];
|
|
914
914
|
if (r === void 0) continue;
|
|
915
|
-
let i =
|
|
915
|
+
let i = Vt(t, r);
|
|
916
916
|
i !== void 0 && (e[t] = i);
|
|
917
917
|
}
|
|
918
918
|
return e;
|
|
919
919
|
}
|
|
920
|
-
function
|
|
920
|
+
function Ut() {
|
|
921
921
|
let e = {};
|
|
922
|
-
for (let t of Object.keys(
|
|
923
|
-
let n =
|
|
922
|
+
for (let t of Object.keys(Ht())) {
|
|
923
|
+
let n = $e[t];
|
|
924
924
|
n && (e[t] = n);
|
|
925
925
|
}
|
|
926
926
|
return e;
|
|
927
927
|
}
|
|
928
|
-
function
|
|
928
|
+
function N(e) {
|
|
929
929
|
return typeof e == "object" && e && !Array.isArray(e) ? e : null;
|
|
930
930
|
}
|
|
931
|
-
function Ut(e) {
|
|
932
|
-
let t = P(Ge().provider);
|
|
933
|
-
return t ? P(t[e]) ?? {} : {};
|
|
934
|
-
}
|
|
935
931
|
function Wt(e) {
|
|
936
|
-
|
|
932
|
+
let t = N(qe().provider);
|
|
933
|
+
return t ? N(t[e]) ?? {} : {};
|
|
934
|
+
}
|
|
935
|
+
function Gt(e) {
|
|
936
|
+
return Object.keys(Wt(e)).length > 0;
|
|
937
937
|
}
|
|
938
|
-
function
|
|
939
|
-
let e =
|
|
938
|
+
function Kt() {
|
|
939
|
+
let e = N(qe().provider);
|
|
940
940
|
return e ? new Set(Object.keys(e)) : /* @__PURE__ */ new Set();
|
|
941
941
|
}
|
|
942
|
-
var
|
|
942
|
+
var qt = /* @__PURE__ */ new Set([
|
|
943
943
|
"openai",
|
|
944
944
|
"anthropic",
|
|
945
945
|
"opencode"
|
|
946
946
|
]);
|
|
947
|
-
function
|
|
947
|
+
function Jt(e) {
|
|
948
948
|
return typeof e != "string" || !e.includes("/") ? null : e.split("/")[0]?.trim().toLowerCase() || null;
|
|
949
949
|
}
|
|
950
|
-
function
|
|
951
|
-
let e =
|
|
950
|
+
function Yt() {
|
|
951
|
+
let e = Kt(), t = qe();
|
|
952
952
|
for (let n of ["model", "small_model"]) {
|
|
953
|
-
let r =
|
|
953
|
+
let r = Jt(t[n]);
|
|
954
954
|
r && e.add(r);
|
|
955
955
|
}
|
|
956
956
|
return e;
|
|
957
957
|
}
|
|
958
|
-
function
|
|
959
|
-
let e =
|
|
960
|
-
for (let t of
|
|
958
|
+
function Xt() {
|
|
959
|
+
let e = Yt();
|
|
960
|
+
for (let t of qt) e.add(t);
|
|
961
961
|
return Array.from(e).sort((e, t) => e.localeCompare(t));
|
|
962
962
|
}
|
|
963
|
-
function Xt(e) {
|
|
964
|
-
let t = qt(e);
|
|
965
|
-
return t && Kt.has(t) ? t : null;
|
|
966
|
-
}
|
|
967
963
|
function Zt(e) {
|
|
964
|
+
let t = Jt(e);
|
|
965
|
+
return t && qt.has(t) ? t : null;
|
|
966
|
+
}
|
|
967
|
+
function Qt(e) {
|
|
968
968
|
return e === "openai" ? "gpt-6-luna" : e === "anthropic" ? "claude-haiku-4-5" : e === "opencode" ? "opencode/gpt-6-luna" : null;
|
|
969
969
|
}
|
|
970
|
-
function
|
|
970
|
+
function $t(e, t) {
|
|
971
971
|
if (e !== "opencode") return [
|
|
972
972
|
null,
|
|
973
|
-
t ||
|
|
973
|
+
t || Qt(e),
|
|
974
974
|
{}
|
|
975
975
|
];
|
|
976
|
-
let n = t ||
|
|
976
|
+
let n = t || Qt(e) || "", r = `${e}/`;
|
|
977
977
|
return [
|
|
978
978
|
"https://opencode.ai/zen/v1",
|
|
979
979
|
(n.toLowerCase().startsWith(r) ? n.slice(r.length) : n) || null,
|
|
980
980
|
{}
|
|
981
981
|
];
|
|
982
982
|
}
|
|
983
|
-
function
|
|
983
|
+
function en(e, t) {
|
|
984
984
|
if (!e?.includes("/")) return null;
|
|
985
985
|
let n = e.split("/")[0] ?? "";
|
|
986
986
|
if (!n) return null;
|
|
@@ -988,10 +988,10 @@ function $t(e, t) {
|
|
|
988
988
|
let r = n.toLowerCase();
|
|
989
989
|
return [...t].find((e) => e.toLowerCase() === r) ?? null;
|
|
990
990
|
}
|
|
991
|
-
function en(e) {
|
|
992
|
-
return nn(tn(e));
|
|
993
|
-
}
|
|
994
991
|
function tn(e) {
|
|
992
|
+
return rn(nn(e));
|
|
993
|
+
}
|
|
994
|
+
function nn(e) {
|
|
995
995
|
let t = "";
|
|
996
996
|
for (let n = 0; n < e.length; n++) {
|
|
997
997
|
if (e[n] !== "$" || n === e.length - 1) {
|
|
@@ -1021,7 +1021,7 @@ function tn(e) {
|
|
|
1021
1021
|
}
|
|
1022
1022
|
return t;
|
|
1023
1023
|
}
|
|
1024
|
-
function
|
|
1024
|
+
function rn(e) {
|
|
1025
1025
|
if (!e.includes("{file:")) return e;
|
|
1026
1026
|
let t = "", n = 0;
|
|
1027
1027
|
for (; n < e.length;) {
|
|
@@ -1041,7 +1041,7 @@ function nn(e) {
|
|
|
1041
1041
|
t += a, n = i + 1;
|
|
1042
1042
|
continue;
|
|
1043
1043
|
}
|
|
1044
|
-
let s =
|
|
1044
|
+
let s = nn(o), c = s.startsWith("~") ? `${E()}${s.slice(1)}` : s;
|
|
1045
1045
|
try {
|
|
1046
1046
|
t += m(c, "utf-8").trim();
|
|
1047
1047
|
} catch {
|
|
@@ -1051,23 +1051,23 @@ function nn(e) {
|
|
|
1051
1051
|
}
|
|
1052
1052
|
return t;
|
|
1053
1053
|
}
|
|
1054
|
-
function
|
|
1055
|
-
return
|
|
1054
|
+
function P(e) {
|
|
1055
|
+
return N(e.options) ?? {};
|
|
1056
1056
|
}
|
|
1057
|
-
function
|
|
1058
|
-
let t =
|
|
1057
|
+
function an(e) {
|
|
1058
|
+
let t = P(e), n = t.baseURL || t.baseUrl || t.base_url || e.base_url;
|
|
1059
1059
|
return typeof n == "string" && n ? n : null;
|
|
1060
1060
|
}
|
|
1061
|
-
function
|
|
1062
|
-
let t = P(
|
|
1061
|
+
function on(e) {
|
|
1062
|
+
let t = N(P(e).headers);
|
|
1063
1063
|
if (!t) return {};
|
|
1064
1064
|
let n = {};
|
|
1065
|
-
for (let [e, r] of Object.entries(t)) typeof e == "string" && typeof r == "string" && (n[e] =
|
|
1065
|
+
for (let [e, r] of Object.entries(t)) typeof e == "string" && typeof r == "string" && (n[e] = tn(r));
|
|
1066
1066
|
return n;
|
|
1067
1067
|
}
|
|
1068
|
-
function
|
|
1069
|
-
let t =
|
|
1070
|
-
if (typeof n == "string" && n) return
|
|
1068
|
+
function sn(e) {
|
|
1069
|
+
let t = P(e), n = t.apiKey || e.apiKey;
|
|
1070
|
+
if (typeof n == "string" && n) return tn(n);
|
|
1071
1071
|
let r = t.apiKeyEnv ?? t.api_key_env;
|
|
1072
1072
|
if (typeof r == "string" && r) {
|
|
1073
1073
|
let e = process.env[r];
|
|
@@ -1075,22 +1075,22 @@ function on(e) {
|
|
|
1075
1075
|
}
|
|
1076
1076
|
return null;
|
|
1077
1077
|
}
|
|
1078
|
-
function
|
|
1079
|
-
let t =
|
|
1078
|
+
function cn(e) {
|
|
1079
|
+
let t = Wt(e), n = P(t), r = n.defaultModel ?? n.default_model ?? t.defaultModel ?? t.default_model;
|
|
1080
1080
|
if (typeof r == "string" && r) return r.startsWith(`${e}/`) ? r : `${e}/${r}`;
|
|
1081
|
-
let i =
|
|
1081
|
+
let i = N(t.models);
|
|
1082
1082
|
if (i) {
|
|
1083
1083
|
let t = Object.keys(i)[0];
|
|
1084
1084
|
if (typeof t == "string" && t) return `${e}/${t}`;
|
|
1085
1085
|
}
|
|
1086
1086
|
return null;
|
|
1087
1087
|
}
|
|
1088
|
-
function
|
|
1089
|
-
let n =
|
|
1090
|
-
a ||=
|
|
1091
|
-
let o = `${e}/`, s = a.toLowerCase().startsWith(o.toLowerCase()) ? a.slice(o.length) : a, c =
|
|
1088
|
+
function ln(e, t) {
|
|
1089
|
+
let n = Wt(e), r = an(n), i = on(n), a = t;
|
|
1090
|
+
a ||= cn(e) ?? "";
|
|
1091
|
+
let o = `${e}/`, s = a.toLowerCase().startsWith(o.toLowerCase()) ? a.slice(o.length) : a, c = N(n.models), l = s;
|
|
1092
1092
|
if (c) {
|
|
1093
|
-
let e =
|
|
1093
|
+
let e = N(c[s]);
|
|
1094
1094
|
e && typeof e.id == "string" && (l = e.id);
|
|
1095
1095
|
}
|
|
1096
1096
|
return (typeof l != "string" || !l) && (l = null), [
|
|
@@ -1101,73 +1101,73 @@ function cn(e, t) {
|
|
|
1101
1101
|
}
|
|
1102
1102
|
//#endregion
|
|
1103
1103
|
//#region src/database-runtime-primitives.ts
|
|
1104
|
-
var
|
|
1104
|
+
var un = 26, dn = [
|
|
1105
1105
|
"memory_items",
|
|
1106
1106
|
"sessions",
|
|
1107
1107
|
"artifacts",
|
|
1108
1108
|
"raw_events",
|
|
1109
1109
|
"raw_event_sessions",
|
|
1110
1110
|
"usage_events"
|
|
1111
|
-
],
|
|
1112
|
-
...
|
|
1111
|
+
], fn = [
|
|
1112
|
+
...dn,
|
|
1113
1113
|
"memory_fts",
|
|
1114
1114
|
"coordinator_enrollment_reconciliation_issues"
|
|
1115
1115
|
];
|
|
1116
|
-
function
|
|
1116
|
+
function pn() {
|
|
1117
1117
|
let e = process.env.CODEMEM_EMBEDDING_DISABLED?.toLowerCase();
|
|
1118
1118
|
return e === "1" || e === "true" || e === "yes";
|
|
1119
1119
|
}
|
|
1120
|
-
function
|
|
1121
|
-
if (!
|
|
1120
|
+
function mn(e) {
|
|
1121
|
+
if (!pn() && (Se.load(e), !e.prepare("SELECT vec_version() AS v").get()?.v)) throw Error("sqlite-vec loaded but version check failed");
|
|
1122
1122
|
}
|
|
1123
|
-
function
|
|
1123
|
+
function F(e) {
|
|
1124
1124
|
let t = e.pragma("user_version", { simple: !0 });
|
|
1125
1125
|
return typeof t == "number" ? t : 0;
|
|
1126
1126
|
}
|
|
1127
|
-
var
|
|
1127
|
+
var hn = [{
|
|
1128
1128
|
name: "trg_identity_devices_assignment_version",
|
|
1129
1129
|
create: "CREATE TRIGGER trg_identity_devices_assignment_version\n AFTER UPDATE OF identity_id ON identity_devices\n WHEN NEW.identity_id <> OLD.identity_id\n BEGIN\n UPDATE identity_devices\n SET assignment_version = OLD.assignment_version + 1\n WHERE device_id = NEW.device_id;\n END"
|
|
1130
1130
|
}, {
|
|
1131
1131
|
name: "trg_identity_devices_purge_decisions",
|
|
1132
1132
|
create: "CREATE TRIGGER trg_identity_devices_purge_decisions\n AFTER DELETE ON identity_devices\n BEGIN\n DELETE FROM policy_team_device_decisions WHERE device_id = OLD.device_id;\n END"
|
|
1133
|
-
}],
|
|
1134
|
-
function
|
|
1133
|
+
}], gn = hn.map(({ name: e, create: t }) => `DROP TRIGGER IF EXISTS ${e};\n${t};`).join("\n");
|
|
1134
|
+
function _n(e) {
|
|
1135
1135
|
return e.replace(/\s+/g, " ").trim();
|
|
1136
1136
|
}
|
|
1137
|
-
function
|
|
1137
|
+
function vn(e) {
|
|
1138
1138
|
let t = e.prepare("SELECT sql FROM sqlite_master WHERE type = 'trigger' AND name = ?");
|
|
1139
|
-
return
|
|
1139
|
+
return hn.every(({ name: e, create: n }) => {
|
|
1140
1140
|
let r = t.get(e);
|
|
1141
|
-
return typeof r?.sql == "string" &&
|
|
1141
|
+
return typeof r?.sql == "string" && _n(r.sql) === _n(n);
|
|
1142
1142
|
});
|
|
1143
1143
|
}
|
|
1144
1144
|
//#endregion
|
|
1145
1145
|
//#region src/memory-retirement-delivery-schema.ts
|
|
1146
|
-
function
|
|
1146
|
+
function yn(e) {
|
|
1147
1147
|
e.exec("CREATE TABLE IF NOT EXISTS memory_retirement_deliveries (\n control_id TEXT NOT NULL,\n peer_device_id TEXT NOT NULL,\n entity_id TEXT NOT NULL,\n source_device_id TEXT NOT NULL,\n retired_scope_id TEXT NOT NULL,\n acknowledged_at TEXT,\n PRIMARY KEY (control_id, peer_device_id)\n );\n CREATE INDEX IF NOT EXISTS idx_memory_retirement_deliveries_pending\n ON memory_retirement_deliveries(peer_device_id, source_device_id, acknowledged_at, control_id);\n CREATE TABLE IF NOT EXISTS memory_retirement_peer_trust (\n local_device_id TEXT NOT NULL,\n peer_device_id TEXT NOT NULL,\n public_key TEXT NOT NULL,\n pinned_fingerprint TEXT NOT NULL,\n PRIMARY KEY (local_device_id, peer_device_id)\n );\n CREATE TABLE IF NOT EXISTS memory_retirement_receipts (\n control_id TEXT PRIMARY KEY,\n source_device_id TEXT NOT NULL,\n received_at TEXT NOT NULL\n );\n CREATE TABLE IF NOT EXISTS memory_retirement_reset_receivers (\n reset_id TEXT PRIMARY KEY, source_device_id TEXT NOT NULL, source_public_key TEXT NOT NULL,\n local_device_id TEXT NOT NULL, boundary TEXT NOT NULL, next_offset INTEGER NOT NULL DEFAULT 0,\n complete INTEGER NOT NULL DEFAULT 0, last_page_digest TEXT\n );\n CREATE TABLE IF NOT EXISTS memory_retirement_reset_manifests (\n reset_id TEXT NOT NULL, peer_device_id TEXT NOT NULL, source_device_id TEXT NOT NULL,\n boundary TEXT NOT NULL, controls_json TEXT NOT NULL,\n PRIMARY KEY(reset_id, peer_device_id, source_device_id)\n );");
|
|
1148
1148
|
}
|
|
1149
1149
|
//#endregion
|
|
1150
1150
|
//#region src/memory-scope-retirement.ts
|
|
1151
|
-
function
|
|
1151
|
+
function bn(e) {
|
|
1152
1152
|
e.exec("CREATE TABLE IF NOT EXISTS memory_scope_retirements (\n entity_id TEXT NOT NULL,\n source_device_id TEXT NOT NULL,\n retired_scope_id TEXT NOT NULL,\n retired_at TEXT NOT NULL,\n PRIMARY KEY (entity_id, retired_scope_id)\n );\n CREATE TRIGGER IF NOT EXISTS memory_scope_retirements_no_update\n BEFORE UPDATE ON memory_scope_retirements\n BEGIN SELECT RAISE(ABORT, 'memory_retirement_immutable'); END;\n CREATE TRIGGER IF NOT EXISTS memory_scope_retirements_no_delete\n BEFORE DELETE ON memory_scope_retirements\n BEGIN SELECT RAISE(ABORT, 'memory_retirement_immutable'); END;\n CREATE TRIGGER IF NOT EXISTS memory_scope_retirements_no_replace\n BEFORE INSERT ON memory_scope_retirements\n WHEN EXISTS (SELECT 1 FROM memory_scope_retirements WHERE entity_id = NEW.entity_id AND retired_scope_id = NEW.retired_scope_id)\n BEGIN SELECT RAISE(ABORT, 'memory_retirement_immutable'); END;");
|
|
1153
1153
|
}
|
|
1154
|
-
function
|
|
1154
|
+
function xn(e, t, n) {
|
|
1155
1155
|
return n ? !!e.prepare("SELECT 1 FROM memory_scope_retirements WHERE entity_id = ? AND retired_scope_id = ?").get(t, n) : !1;
|
|
1156
1156
|
}
|
|
1157
|
-
function
|
|
1158
|
-
if (
|
|
1157
|
+
function Sn(e, t, n) {
|
|
1158
|
+
if (xn(e, t, n)) throw Error("memory_scope_retired");
|
|
1159
1159
|
}
|
|
1160
|
-
function
|
|
1160
|
+
function Cn(e, t) {
|
|
1161
1161
|
return !!e.prepare("SELECT 1 FROM memory_scope_retirements WHERE entity_id = ? LIMIT 1").get(t);
|
|
1162
1162
|
}
|
|
1163
1163
|
//#endregion
|
|
1164
1164
|
//#region src/memory-ownership-recovery-schema.ts
|
|
1165
|
-
function
|
|
1166
|
-
|
|
1165
|
+
function wn(e) {
|
|
1166
|
+
Re(e), bn(e), yn(e), e.exec("CREATE TABLE IF NOT EXISTS memory_ownership_recoveries (\n operation_id TEXT PRIMARY KEY,\n actor_id TEXT NOT NULL,\n device_id TEXT NOT NULL,\n request_json TEXT NOT NULL,\n reviewed_digest TEXT NOT NULL,\n result_json TEXT NOT NULL,\n created_at TEXT NOT NULL\n );");
|
|
1167
1167
|
}
|
|
1168
1168
|
//#endregion
|
|
1169
1169
|
//#region src/memory-reference-schema.ts
|
|
1170
|
-
var
|
|
1170
|
+
var Tn = [{
|
|
1171
1171
|
name: "memory_file_refs",
|
|
1172
1172
|
columns: [
|
|
1173
1173
|
"memory_id",
|
|
@@ -1184,9 +1184,9 @@ var wn = [{
|
|
|
1184
1184
|
index: "idx_memory_concept_refs_concept",
|
|
1185
1185
|
indexDdl: "CREATE INDEX IF NOT EXISTS idx_memory_concept_refs_concept ON memory_concept_refs(concept)"
|
|
1186
1186
|
}];
|
|
1187
|
-
function
|
|
1187
|
+
function En(e) {
|
|
1188
1188
|
let t = /* @__PURE__ */ new Set();
|
|
1189
|
-
for (let n of
|
|
1189
|
+
for (let n of Tn) {
|
|
1190
1190
|
let r = e.prepare("SELECT type FROM sqlite_master WHERE name = ? AND type IN ('table', 'view')").get(n.name);
|
|
1191
1191
|
if (!r) continue;
|
|
1192
1192
|
if (r.type !== "table") throw Error(`memory_reference_schema_incompatible:${n.name}:expected_table`);
|
|
@@ -1196,39 +1196,39 @@ function Tn(e) {
|
|
|
1196
1196
|
}
|
|
1197
1197
|
return t;
|
|
1198
1198
|
}
|
|
1199
|
-
function
|
|
1200
|
-
for (let t of
|
|
1199
|
+
function Dn(e) {
|
|
1200
|
+
for (let t of Tn) try {
|
|
1201
1201
|
e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'index' AND name = ?").get(t.index) || e.exec(t.indexDdl);
|
|
1202
1202
|
} catch {}
|
|
1203
1203
|
}
|
|
1204
|
-
function
|
|
1205
|
-
let t =
|
|
1206
|
-
for (let n of
|
|
1207
|
-
|
|
1204
|
+
function On(e) {
|
|
1205
|
+
let t = En(e);
|
|
1206
|
+
for (let n of Tn) t.has(n.name) || e.exec(n.ddl);
|
|
1207
|
+
Dn(e);
|
|
1208
1208
|
}
|
|
1209
1209
|
//#endregion
|
|
1210
1210
|
//#region src/peer-project-filter-management.ts
|
|
1211
|
-
function
|
|
1211
|
+
function kn(e) {
|
|
1212
1212
|
e.prepare("SELECT 1 FROM sqlite_master WHERE name = 'peer_project_filter_management' AND type = 'table'").get() || e.exec("CREATE TABLE IF NOT EXISTS peer_project_filter_management (id INTEGER PRIMARY KEY CHECK (id = 1))");
|
|
1213
1213
|
}
|
|
1214
|
-
function
|
|
1214
|
+
function An(e) {
|
|
1215
1215
|
e.prepare("INSERT INTO peer_project_filter_management (id) VALUES (1) ON CONFLICT(id) DO NOTHING").run();
|
|
1216
1216
|
}
|
|
1217
|
-
function
|
|
1217
|
+
function jn(e) {
|
|
1218
1218
|
return e.prepare("SELECT EXISTS (SELECT 1 FROM peer_project_filter_management)\n OR EXISTS (SELECT 1 FROM replication_scopes WHERE authority_type = 'coordinator')\n OR EXISTS (SELECT 1 FROM scope_membership_cache_state)").pluck().get() === 1;
|
|
1219
1219
|
}
|
|
1220
1220
|
//#endregion
|
|
1221
1221
|
//#region src/peer-project-filter-retention.ts
|
|
1222
|
-
var
|
|
1223
|
-
function
|
|
1224
|
-
e.prepare("SELECT 1 FROM sqlite_master WHERE name = 'sync_peers' AND type = 'table'").get() && e.prepare("SELECT COUNT(*) FROM sqlite_master\n WHERE (type = 'table' AND name = 'peer_project_filter_retention')\n OR (type = 'trigger' AND name IN (?, ?))").pluck().get(...
|
|
1222
|
+
var Mn = "\nCREATE TABLE IF NOT EXISTS peer_project_filter_retention (\n peer_device_id TEXT PRIMARY KEY NOT NULL,\n projects_include_json TEXT,\n projects_exclude_json TEXT\n);\n\nCREATE TRIGGER IF NOT EXISTS peer_project_filters_retain_before_delete\nBEFORE DELETE ON sync_peers\nBEGIN\n INSERT INTO peer_project_filter_retention (\n peer_device_id, projects_include_json, projects_exclude_json\n ) VALUES (OLD.peer_device_id, OLD.projects_include_json, OLD.projects_exclude_json)\n ON CONFLICT(peer_device_id) DO UPDATE SET\n projects_include_json = excluded.projects_include_json,\n projects_exclude_json = excluded.projects_exclude_json;\nEND;\n\nCREATE TRIGGER IF NOT EXISTS peer_project_filters_restore_after_insert\nAFTER INSERT ON sync_peers\nWHEN NEW.projects_include_json IS NULL AND NEW.projects_exclude_json IS NULL\nBEGIN\n UPDATE sync_peers SET\n projects_include_json = (\n SELECT projects_include_json FROM peer_project_filter_retention\n WHERE peer_device_id = NEW.peer_device_id\n ),\n projects_exclude_json = (\n SELECT projects_exclude_json FROM peer_project_filter_retention\n WHERE peer_device_id = NEW.peer_device_id\n )\n WHERE peer_device_id = NEW.peer_device_id\n AND EXISTS (\n SELECT 1 FROM peer_project_filter_retention WHERE peer_device_id = NEW.peer_device_id\n );\nEND;\n", Nn = ["peer_project_filters_retain_before_delete", "peer_project_filters_restore_after_insert"];
|
|
1223
|
+
function Pn(e) {
|
|
1224
|
+
e.prepare("SELECT 1 FROM sqlite_master WHERE name = 'sync_peers' AND type = 'table'").get() && e.prepare("SELECT COUNT(*) FROM sqlite_master\n WHERE (type = 'table' AND name = 'peer_project_filter_retention')\n OR (type = 'trigger' AND name IN (?, ?))").pluck().get(...Nn) !== 3 && e.transaction(() => e.exec(Mn)).immediate();
|
|
1225
1225
|
}
|
|
1226
|
-
function
|
|
1226
|
+
function Fn(e, t) {
|
|
1227
1227
|
return e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'peer_project_filter_retention'").get() ? e.prepare("SELECT projects_include_json, projects_exclude_json FROM peer_project_filter_retention\n WHERE peer_device_id = ?").get(t) ?? null : null;
|
|
1228
1228
|
}
|
|
1229
1229
|
//#endregion
|
|
1230
1230
|
//#region src/peer-removal-check-state.ts
|
|
1231
|
-
var
|
|
1231
|
+
var I = "sync_peer_removal_check_state", In = `UPDATE ${I} SET generation = generation + 1, applied_removal_seq = 0 WHERE id = 1`, Ln = [
|
|
1232
1232
|
[
|
|
1233
1233
|
"pairing_insert",
|
|
1234
1234
|
"AFTER INSERT ON sync_peers",
|
|
@@ -1252,8 +1252,8 @@ var L = "sync_peer_removal_check_state", Fn = `UPDATE ${L} SET generation = gene
|
|
|
1252
1252
|
].map(([e, t, n]) => ({
|
|
1253
1253
|
name: `sync_peer_removal_generation_${e}`,
|
|
1254
1254
|
sql: `CREATE TRIGGER sync_peer_removal_generation_${e} ${t} ${n}
|
|
1255
|
-
BEGIN ${
|
|
1256
|
-
})),
|
|
1255
|
+
BEGIN ${In}; END`
|
|
1256
|
+
})), Rn = {
|
|
1257
1257
|
sync_peers: [
|
|
1258
1258
|
"peer_device_id",
|
|
1259
1259
|
"public_key",
|
|
@@ -1261,75 +1261,75 @@ var L = "sync_peer_removal_check_state", Fn = `UPDATE ${L} SET generation = gene
|
|
|
1261
1261
|
],
|
|
1262
1262
|
identity_devices: ["device_id", "status"]
|
|
1263
1263
|
};
|
|
1264
|
-
function
|
|
1265
|
-
return Object.entries(
|
|
1264
|
+
function zn(e) {
|
|
1265
|
+
return Object.entries(Rn).every(([t, n]) => {
|
|
1266
1266
|
let r = e.prepare(`PRAGMA table_info(${t})`).all();
|
|
1267
1267
|
return n.every((e) => r.some((t) => t.name === e));
|
|
1268
1268
|
});
|
|
1269
1269
|
}
|
|
1270
|
-
function
|
|
1270
|
+
function Bn(e) {
|
|
1271
1271
|
let t = e.prepare("SELECT sql FROM sqlite_schema WHERE type = 'trigger' AND name = ?");
|
|
1272
|
-
return
|
|
1272
|
+
return Ln.every(({ name: e, sql: n }) => t.get(e)?.sql === n);
|
|
1273
1273
|
}
|
|
1274
|
-
function
|
|
1275
|
-
if (!e.prepare("SELECT 1 FROM sqlite_schema WHERE type = 'table' AND name = ?").get(
|
|
1276
|
-
let t = e.prepare(`SELECT generation, applied_removal_seq FROM ${
|
|
1274
|
+
function Vn(e) {
|
|
1275
|
+
if (!e.prepare("SELECT 1 FROM sqlite_schema WHERE type = 'table' AND name = ?").get(I) || !Bn(e)) return null;
|
|
1276
|
+
let t = e.prepare(`SELECT generation, applied_removal_seq FROM ${I} WHERE id = 1`).get();
|
|
1277
1277
|
return t ? {
|
|
1278
1278
|
generation: t.generation,
|
|
1279
1279
|
appliedRemovalSeq: t.applied_removal_seq
|
|
1280
1280
|
} : null;
|
|
1281
1281
|
}
|
|
1282
|
-
function
|
|
1283
|
-
e.readonly || !
|
|
1284
|
-
e.exec(`CREATE TABLE IF NOT EXISTS ${
|
|
1282
|
+
function Hn(e) {
|
|
1283
|
+
e.readonly || !zn(e) || Vn(e) || e.transaction(() => {
|
|
1284
|
+
e.exec(`CREATE TABLE IF NOT EXISTS ${I} (
|
|
1285
1285
|
id INTEGER PRIMARY KEY CHECK (id = 1),
|
|
1286
1286
|
generation INTEGER NOT NULL DEFAULT 0,
|
|
1287
1287
|
applied_removal_seq INTEGER NOT NULL DEFAULT 0
|
|
1288
|
-
)`), e.prepare(`INSERT OR IGNORE INTO ${
|
|
1289
|
-
for (let { name: t, sql: n } of
|
|
1290
|
-
e.exec(
|
|
1288
|
+
)`), e.prepare(`INSERT OR IGNORE INTO ${I}(id) VALUES (1)`).run();
|
|
1289
|
+
for (let { name: t, sql: n } of Ln) e.exec(`DROP TRIGGER IF EXISTS ${t}`), e.exec(n);
|
|
1290
|
+
e.exec(In);
|
|
1291
1291
|
}).immediate();
|
|
1292
1292
|
}
|
|
1293
|
-
function
|
|
1294
|
-
return
|
|
1293
|
+
function Un(e) {
|
|
1294
|
+
return Vn(e)?.appliedRemovalSeq ?? 0;
|
|
1295
1295
|
}
|
|
1296
|
-
function
|
|
1297
|
-
return
|
|
1296
|
+
function Wn(e, t) {
|
|
1297
|
+
return Vn(e) ? e.prepare(`UPDATE ${I} SET applied_removal_seq = ? WHERE id = 1 AND generation = ?`).run(t.removalSeq, t.generation).changes === 1 : !1;
|
|
1298
1298
|
}
|
|
1299
1299
|
//#endregion
|
|
1300
1300
|
//#region src/raw-event-flush-claim-schema.ts
|
|
1301
|
-
function
|
|
1301
|
+
function Gn(e) {
|
|
1302
1302
|
return e.prepare("SELECT 1 FROM pragma_table_info('raw_event_flush_batches') WHERE name = 'claim_generation'").get() !== void 0;
|
|
1303
1303
|
}
|
|
1304
|
-
function
|
|
1305
|
-
if (e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'raw_event_flush_batches'").get() && !
|
|
1304
|
+
function Kn(e) {
|
|
1305
|
+
if (e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'raw_event_flush_batches'").get() && !Gn(e)) {
|
|
1306
1306
|
if (e.readonly) throw Error("Raw-event claim schema requires a writable database upgrade");
|
|
1307
1307
|
try {
|
|
1308
1308
|
e.exec("ALTER TABLE raw_event_flush_batches ADD COLUMN claim_generation INTEGER NOT NULL DEFAULT 0");
|
|
1309
1309
|
} catch (t) {
|
|
1310
|
-
if (!
|
|
1310
|
+
if (!Gn(e)) throw t;
|
|
1311
1311
|
}
|
|
1312
|
-
if (!
|
|
1312
|
+
if (!Gn(e)) throw Error("Raw-event claim generation is missing after upgrade");
|
|
1313
1313
|
}
|
|
1314
1314
|
}
|
|
1315
1315
|
//#endregion
|
|
1316
1316
|
//#region src/relay-service-pin-store.ts
|
|
1317
|
-
var
|
|
1318
|
-
function
|
|
1319
|
-
|
|
1320
|
-
}
|
|
1321
|
-
function qn(e, t, n) {
|
|
1322
|
-
return e.prepare("SELECT * FROM sync_relay_service_pins WHERE coordinator_id = ? AND group_id = ?").get(t, n);
|
|
1317
|
+
var qn = /* @__PURE__ */ new WeakSet();
|
|
1318
|
+
function L(e) {
|
|
1319
|
+
qn.has(e) || (e.exec("\n CREATE TABLE IF NOT EXISTS sync_relay_service_pins (\n coordinator_id TEXT NOT NULL,\n group_id TEXT NOT NULL,\n pinned_key TEXT NOT NULL,\n first_seen_at TEXT NOT NULL,\n state TEXT NOT NULL CHECK(state IN ('pinned', 'pending_change')),\n candidate_key TEXT,\n candidate_seen_at TEXT,\n last_candidate_key TEXT,\n last_candidate_seen_at TEXT,\n updated_at TEXT NOT NULL,\n PRIMARY KEY(coordinator_id, group_id)\n );\n "), e.inTransaction || qn.add(e));
|
|
1323
1320
|
}
|
|
1324
1321
|
function Jn(e, t, n) {
|
|
1325
|
-
|
|
1326
|
-
let r = qn(e, t, n);
|
|
1327
|
-
return r ? Xn(r) : null;
|
|
1322
|
+
return e.prepare("SELECT * FROM sync_relay_service_pins WHERE coordinator_id = ? AND group_id = ?").get(t, n);
|
|
1328
1323
|
}
|
|
1329
|
-
function Yn(e) {
|
|
1330
|
-
|
|
1324
|
+
function Yn(e, t, n) {
|
|
1325
|
+
L(e);
|
|
1326
|
+
let r = Jn(e, t, n);
|
|
1327
|
+
return r ? Zn(r) : null;
|
|
1331
1328
|
}
|
|
1332
1329
|
function Xn(e) {
|
|
1330
|
+
return L(e), e.prepare("SELECT * FROM sync_relay_service_pins ORDER BY coordinator_id, group_id").all().map(Zn);
|
|
1331
|
+
}
|
|
1332
|
+
function Zn(e) {
|
|
1333
1333
|
return {
|
|
1334
1334
|
coordinatorId: e.coordinator_id,
|
|
1335
1335
|
groupId: e.group_id,
|
|
@@ -1342,37 +1342,37 @@ function Xn(e) {
|
|
|
1342
1342
|
lastCandidateSeenAt: e.last_candidate_seen_at
|
|
1343
1343
|
};
|
|
1344
1344
|
}
|
|
1345
|
-
function
|
|
1345
|
+
function Qn(e, t, n, r, i) {
|
|
1346
1346
|
e.prepare("INSERT INTO sync_relay_service_pins(\n coordinator_id, group_id, pinned_key, first_seen_at, state,\n candidate_key, candidate_seen_at, updated_at\n ) VALUES (?, ?, ?, ?, 'pinned', NULL, NULL, ?)\n ON CONFLICT(coordinator_id, group_id) DO UPDATE SET\n last_candidate_seen_at = CASE WHEN candidate_key IS NOT NULL\n AND candidate_key != excluded.pinned_key\n THEN candidate_seen_at ELSE last_candidate_seen_at END,\n last_candidate_key = CASE WHEN candidate_key IS NOT NULL\n AND candidate_key != excluded.pinned_key\n THEN candidate_key ELSE last_candidate_key END,\n first_seen_at = CASE WHEN pinned_key = excluded.pinned_key\n THEN first_seen_at ELSE excluded.first_seen_at END,\n pinned_key = excluded.pinned_key,\n state = 'pinned',\n candidate_key = NULL,\n candidate_seen_at = NULL,\n updated_at = excluded.updated_at").run(t, n, r, i, i);
|
|
1347
1347
|
}
|
|
1348
|
-
function
|
|
1348
|
+
function $n(e, t, n, r) {
|
|
1349
1349
|
let i = t.candidate_key === n ? t.candidate_seen_at ?? r : r;
|
|
1350
1350
|
e.prepare("UPDATE sync_relay_service_pins\n SET state = 'pending_change', candidate_key = ?, candidate_seen_at = ?, updated_at = ?\n WHERE coordinator_id = ? AND group_id = ?").run(n, i, r, t.coordinator_id, t.group_id);
|
|
1351
1351
|
}
|
|
1352
|
-
function
|
|
1353
|
-
|
|
1352
|
+
function er(e, t) {
|
|
1353
|
+
L(e);
|
|
1354
1354
|
let { coordinatorId: n, groupId: r, advertisedKey: i, operatorKey: a } = t, o = (t.now ?? /* @__PURE__ */ new Date()).toISOString();
|
|
1355
1355
|
return e.transaction(() => {
|
|
1356
|
-
let t =
|
|
1356
|
+
let t = Jn(e, n, r);
|
|
1357
1357
|
if (a !== void 0 || !t) {
|
|
1358
1358
|
let t = a ?? i;
|
|
1359
|
-
return
|
|
1359
|
+
return Qn(e, n, r, t, o), {
|
|
1360
1360
|
status: "pinned",
|
|
1361
1361
|
key: t
|
|
1362
1362
|
};
|
|
1363
1363
|
}
|
|
1364
|
-
return t.pinned_key === i ? (t.state !== "pinned" &&
|
|
1364
|
+
return t.pinned_key === i ? (t.state !== "pinned" && Qn(e, n, r, i, o), {
|
|
1365
1365
|
status: "pinned",
|
|
1366
1366
|
key: t.pinned_key
|
|
1367
|
-
}) : (
|
|
1367
|
+
}) : ($n(e, t, i, o), {
|
|
1368
1368
|
status: "paused",
|
|
1369
1369
|
pinnedKey: t.pinned_key,
|
|
1370
1370
|
candidateKey: i
|
|
1371
1371
|
});
|
|
1372
1372
|
}).immediate();
|
|
1373
1373
|
}
|
|
1374
|
-
function
|
|
1375
|
-
|
|
1374
|
+
function tr(e, t) {
|
|
1375
|
+
L(e);
|
|
1376
1376
|
let n = te(t.candidateKey);
|
|
1377
1377
|
if (!n) return !1;
|
|
1378
1378
|
let r = (t.now ?? /* @__PURE__ */ new Date()).toISOString();
|
|
@@ -1380,34 +1380,34 @@ function er(e, t) {
|
|
|
1380
1380
|
}
|
|
1381
1381
|
//#endregion
|
|
1382
1382
|
//#region src/sync-channel-progress.ts
|
|
1383
|
-
function
|
|
1383
|
+
function nr(e) {
|
|
1384
1384
|
e.exec("CREATE TABLE IF NOT EXISTS sync_channel_progress (\n peer_device_id TEXT NOT NULL,\n scope_id TEXT NOT NULL,\n generation INTEGER NOT NULL,\n snapshot_id TEXT NOT NULL,\n baseline_cursor TEXT,\n last_acked_cursor TEXT,\n PRIMARY KEY (peer_device_id, scope_id)\n )");
|
|
1385
1385
|
}
|
|
1386
|
-
function nr(e, t, n) {
|
|
1387
|
-
return tr(e), e.prepare("SELECT generation, snapshot_id, baseline_cursor, last_acked_cursor\n FROM sync_channel_progress WHERE peer_device_id = ? AND scope_id = ?").get(t, n) ?? null;
|
|
1388
|
-
}
|
|
1389
1386
|
function rr(e, t, n) {
|
|
1390
|
-
|
|
1387
|
+
return nr(e), e.prepare("SELECT generation, snapshot_id, baseline_cursor, last_acked_cursor\n FROM sync_channel_progress WHERE peer_device_id = ? AND scope_id = ?").get(t, n) ?? null;
|
|
1391
1388
|
}
|
|
1392
|
-
function ir(e) {
|
|
1389
|
+
function ir(e, t, n) {
|
|
1390
|
+
nr(e), e.prepare("DELETE FROM sync_channel_progress WHERE peer_device_id = ? AND scope_id = ?").run(t, n);
|
|
1391
|
+
}
|
|
1392
|
+
function ar(e) {
|
|
1393
1393
|
return e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'sync_channel_progress'").get() !== void 0;
|
|
1394
1394
|
}
|
|
1395
|
-
function
|
|
1396
|
-
return
|
|
1395
|
+
function or(e, t) {
|
|
1396
|
+
return ar(e) ? e.prepare("DELETE FROM sync_channel_progress WHERE peer_device_id = ?").run(t).changes : 0;
|
|
1397
1397
|
}
|
|
1398
|
-
function
|
|
1399
|
-
return
|
|
1398
|
+
function sr(e) {
|
|
1399
|
+
return ar(e) ? e.prepare("DELETE FROM sync_channel_progress AS progress\n WHERE NOT EXISTS (\n SELECT 1 FROM sync_peers peer WHERE peer.peer_device_id = progress.peer_device_id\n )").run().changes : 0;
|
|
1400
1400
|
}
|
|
1401
|
-
function
|
|
1401
|
+
function cr(e, t) {
|
|
1402
1402
|
return e !== null && e.generation === t.generation && e.snapshot_id === t.snapshot_id && e.baseline_cursor === t.baseline_cursor;
|
|
1403
1403
|
}
|
|
1404
|
-
var
|
|
1405
|
-
function
|
|
1406
|
-
|
|
1404
|
+
var lr = "EXISTS (SELECT 1 FROM sync_peers WHERE peer_device_id = ?)";
|
|
1405
|
+
function ur(e, t) {
|
|
1406
|
+
nr(e);
|
|
1407
1407
|
let { peerDeviceId: n, scopeId: r, boundary: i } = t;
|
|
1408
1408
|
e.prepare(`INSERT INTO sync_channel_progress
|
|
1409
1409
|
(peer_device_id, scope_id, generation, snapshot_id, baseline_cursor, last_acked_cursor)
|
|
1410
|
-
SELECT ?, ?, ?, ?, ?, NULL WHERE ${
|
|
1410
|
+
SELECT ?, ?, ?, ?, ?, NULL WHERE ${lr}
|
|
1411
1411
|
ON CONFLICT (peer_device_id, scope_id) DO UPDATE SET
|
|
1412
1412
|
last_acked_cursor = CASE WHEN generation = excluded.generation
|
|
1413
1413
|
AND snapshot_id = excluded.snapshot_id AND baseline_cursor IS excluded.baseline_cursor
|
|
@@ -1415,16 +1415,16 @@ function lr(e, t) {
|
|
|
1415
1415
|
generation = excluded.generation, snapshot_id = excluded.snapshot_id,
|
|
1416
1416
|
baseline_cursor = excluded.baseline_cursor`).run(n, r, i.generation, i.snapshot_id, i.baseline_cursor, n);
|
|
1417
1417
|
}
|
|
1418
|
-
function
|
|
1418
|
+
function dr(e, t) {
|
|
1419
1419
|
let { peerDeviceId: n, scopeId: r, boundary: i, cursor: a } = t;
|
|
1420
1420
|
if (e.prepare(`UPDATE sync_channel_progress SET last_acked_cursor = ?
|
|
1421
1421
|
WHERE peer_device_id = ? AND scope_id = ? AND generation = ? AND snapshot_id = ?
|
|
1422
1422
|
AND baseline_cursor IS ? AND (last_acked_cursor IS NULL OR last_acked_cursor <= ?)
|
|
1423
|
-
AND ${
|
|
1423
|
+
AND ${lr}`).run(a, n, r, i.generation, i.snapshot_id, i.baseline_cursor, a, n).changes !== 1 && e.prepare(`SELECT ${lr}`).pluck().get(n)) throw Error("channel progress changed");
|
|
1424
1424
|
}
|
|
1425
1425
|
//#endregion
|
|
1426
1426
|
//#region src/replication-cursor-orphan-cleanup.ts
|
|
1427
|
-
var
|
|
1427
|
+
var R = "replication_cursor_orphan_cleanup", fr = [
|
|
1428
1428
|
"sync_peers",
|
|
1429
1429
|
"replication_cursors",
|
|
1430
1430
|
"replication_cursors_v2"
|
|
@@ -1433,7 +1433,7 @@ function pr(e, t) {
|
|
|
1433
1433
|
return e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(t) !== void 0;
|
|
1434
1434
|
}
|
|
1435
1435
|
function mr(e) {
|
|
1436
|
-
return pr(e,
|
|
1436
|
+
return pr(e, R) ? e.prepare(`SELECT 1 FROM ${R} WHERE id = 1`).get() !== void 0 : !1;
|
|
1437
1437
|
}
|
|
1438
1438
|
function hr(e, t) {
|
|
1439
1439
|
return e.prepare(`DELETE FROM ${t} AS progress
|
|
@@ -1443,16 +1443,16 @@ function hr(e, t) {
|
|
|
1443
1443
|
}
|
|
1444
1444
|
function gr(e) {
|
|
1445
1445
|
return e.readonly || !fr.every((t) => pr(e, t)) || mr(e) ? null : e.transaction(() => {
|
|
1446
|
-
if (e.exec(`CREATE TABLE IF NOT EXISTS ${
|
|
1446
|
+
if (e.exec(`CREATE TABLE IF NOT EXISTS ${R} (
|
|
1447
1447
|
id INTEGER PRIMARY KEY CHECK (id = 1),
|
|
1448
1448
|
completed_at TEXT NOT NULL
|
|
1449
1449
|
)`), mr(e)) return null;
|
|
1450
1450
|
let t = {
|
|
1451
1451
|
replicationCursors: hr(e, "replication_cursors"),
|
|
1452
1452
|
replicationCursorsV2: hr(e, "replication_cursors_v2"),
|
|
1453
|
-
syncChannelProgress:
|
|
1453
|
+
syncChannelProgress: sr(e)
|
|
1454
1454
|
};
|
|
1455
|
-
return e.prepare(`INSERT INTO ${
|
|
1455
|
+
return e.prepare(`INSERT INTO ${R}(id, completed_at) VALUES (1, ?)`).run((/* @__PURE__ */ new Date()).toISOString()), t;
|
|
1456
1456
|
}).immediate();
|
|
1457
1457
|
}
|
|
1458
1458
|
//#endregion
|
|
@@ -2287,8 +2287,8 @@ CREATE TABLE IF NOT EXISTS scope_membership_cache_state (
|
|
|
2287
2287
|
);
|
|
2288
2288
|
`, Yr = "\nCREATE VIRTUAL TABLE IF NOT EXISTS memory_vectors USING vec0(\n embedding float[384],\n memory_id INTEGER,\n chunk_index INTEGER,\n content_hash TEXT,\n model TEXT\n);\n";
|
|
2289
2289
|
function Xr(e) {
|
|
2290
|
-
if (!
|
|
2291
|
-
Zr(e) ||
|
|
2290
|
+
if (!pn()) try {
|
|
2291
|
+
Zr(e) || mn(e), e.exec(Yr);
|
|
2292
2292
|
} catch {
|
|
2293
2293
|
return;
|
|
2294
2294
|
}
|
|
@@ -2303,7 +2303,7 @@ function Zr(e) {
|
|
|
2303
2303
|
}
|
|
2304
2304
|
function Qr(e) {
|
|
2305
2305
|
e.transaction(() => {
|
|
2306
|
-
e.exec(Mr), e.exec(Jr), Gr(e), pi(e),
|
|
2306
|
+
e.exec(Mr), e.exec(Jr), Gr(e), pi(e), Kn(e), ni(e), ii(e), Hn(e), Pn(e), kn(e), $r(e), ei(e), ti(e), li(e), ui(e), wn(e), Br(e), Pr(e), jr(e), Lr(e), di(e), e.pragma("user_version = 26");
|
|
2307
2307
|
}).immediate(), Xr(e);
|
|
2308
2308
|
}
|
|
2309
2309
|
function $r(e) {
|
|
@@ -2336,7 +2336,7 @@ function ii(e) {
|
|
|
2336
2336
|
z(e, "sync_peers") && (ri(e), z(e, "sync_peer_signature_state") || e.exec("\n CREATE TABLE IF NOT EXISTS sync_peer_signature_state (\n peer_device_id TEXT PRIMARY KEY NOT NULL,\n highest_observed_direct_signature_version INTEGER NOT NULL\n );\n "), e.prepare("SELECT 1 FROM sync_peers AS peer\n LEFT JOIN sync_peer_signature_state AS state USING (peer_device_id)\n WHERE peer.highest_observed_direct_signature_version IS NOT NULL\n AND (state.peer_device_id IS NULL\n OR state.highest_observed_direct_signature_version\n < peer.highest_observed_direct_signature_version)\n LIMIT 1").get() && e.exec("\n INSERT INTO sync_peer_signature_state(\n peer_device_id, highest_observed_direct_signature_version\n )\n SELECT peer_device_id, highest_observed_direct_signature_version\n FROM sync_peers\n WHERE highest_observed_direct_signature_version IS NOT NULL\n ON CONFLICT(peer_device_id) DO UPDATE SET\n highest_observed_direct_signature_version = excluded.highest_observed_direct_signature_version\n WHERE sync_peer_signature_state.highest_observed_direct_signature_version\n < excluded.highest_observed_direct_signature_version;\n "));
|
|
2337
2337
|
}
|
|
2338
2338
|
function ai(e) {
|
|
2339
|
-
e.exec(
|
|
2339
|
+
e.exec(gn);
|
|
2340
2340
|
}
|
|
2341
2341
|
function oi(e) {
|
|
2342
2342
|
if (!z(e, "sessions") || !z(e, "memory_items") || (ci(e), e.exec("DROP TRIGGER IF EXISTS trg_attribution_evidence_delete_orphan"), !B(e, "memory_items", "import_key") || !B(e, "memory_items", "origin_device_id"))) return;
|
|
@@ -2380,7 +2380,7 @@ function ui(e) {
|
|
|
2380
2380
|
}
|
|
2381
2381
|
}
|
|
2382
2382
|
function di(e) {
|
|
2383
|
-
let t =
|
|
2383
|
+
let t = fn.filter((t) => !z(e, t));
|
|
2384
2384
|
if (t.length > 0) throw Error(`Schema bootstrap failed; missing required tables: ${t.join(", ")}`);
|
|
2385
2385
|
}
|
|
2386
2386
|
function fi(e) {
|
|
@@ -2407,7 +2407,7 @@ function mi(e) {
|
|
|
2407
2407
|
!gi(e) && hi(e) && Qr(e);
|
|
2408
2408
|
}
|
|
2409
2409
|
function hi(e) {
|
|
2410
|
-
return
|
|
2410
|
+
return F(e) === 0 && fi(e);
|
|
2411
2411
|
}
|
|
2412
2412
|
function gi(e) {
|
|
2413
2413
|
return e.readonly === !0;
|
|
@@ -2478,13 +2478,13 @@ function xi(e, t, n = {}) {
|
|
|
2478
2478
|
}
|
|
2479
2479
|
//#endregion
|
|
2480
2480
|
//#region src/db.ts
|
|
2481
|
-
var Si = 6, H = g(
|
|
2481
|
+
var Si = 6, H = g(ye(), ".codemem", "mem.sqlite");
|
|
2482
2482
|
function Ci(e) {
|
|
2483
|
-
if (e) return
|
|
2483
|
+
if (e) return D(e);
|
|
2484
2484
|
let t = process.env.CODEMEM_DB;
|
|
2485
|
-
return t ?
|
|
2485
|
+
return t ? D(t) : H;
|
|
2486
2486
|
}
|
|
2487
|
-
var wi = [g(
|
|
2487
|
+
var wi = [g(ye(), ".codemem.sqlite"), g(ye(), ".opencode-mem.sqlite")], Ti = ["-wal", "-shm"];
|
|
2488
2488
|
function Ei(e, t) {
|
|
2489
2489
|
le(h(t), { recursive: !0 });
|
|
2490
2490
|
let n = [[e, t], ...Ti.map((n) => [e + n, t + n])];
|
|
@@ -2512,12 +2512,12 @@ function Di(e) {
|
|
|
2512
2512
|
}
|
|
2513
2513
|
function Oi(e = H) {
|
|
2514
2514
|
Di(e), le(h(e), { recursive: !0 });
|
|
2515
|
-
let t = new
|
|
2515
|
+
let t = new xe(e);
|
|
2516
2516
|
try {
|
|
2517
2517
|
t.pragma("foreign_keys = ON"), t.pragma("busy_timeout = 5000");
|
|
2518
2518
|
let e = hi(t) || ji(t);
|
|
2519
2519
|
if (mi(t), !e) return t;
|
|
2520
|
-
if (
|
|
2520
|
+
if (Kn(t), !t.memory) {
|
|
2521
2521
|
let e = t.pragma("journal_mode = WAL", { simple: !0 });
|
|
2522
2522
|
e.toLowerCase() !== "wal" && console.warn(`Failed to enable WAL mode (got ${e}). Concurrent access may not work correctly.`);
|
|
2523
2523
|
}
|
|
@@ -2527,7 +2527,7 @@ function Oi(e = H) {
|
|
|
2527
2527
|
}
|
|
2528
2528
|
}
|
|
2529
2529
|
function ki(e = H, t = {}) {
|
|
2530
|
-
let n = new
|
|
2530
|
+
let n = new xe(e, {
|
|
2531
2531
|
readonly: !0,
|
|
2532
2532
|
fileMustExist: !0
|
|
2533
2533
|
});
|
|
@@ -2538,15 +2538,15 @@ function ki(e = H, t = {}) {
|
|
|
2538
2538
|
}
|
|
2539
2539
|
}
|
|
2540
2540
|
function Ai(e, t = console.warn) {
|
|
2541
|
-
let n =
|
|
2541
|
+
let n = F(e);
|
|
2542
2542
|
if (n === 0) throw Error("Database schema is not initialized (read-only open). Point at an initialized codemem database.");
|
|
2543
2543
|
if (n < 6) throw Error(`Database schema version ${n} is older than minimum compatible (6).`);
|
|
2544
2544
|
n > 26 && t(`Database schema version ${n} is newer than this TS runtime (26). Running in read-only compatibility mode.`);
|
|
2545
|
-
let r =
|
|
2545
|
+
let r = dn.filter((t) => !U(e, t));
|
|
2546
2546
|
if (r.length > 0) throw Error(`Required tables missing: ${r.join(", ")}. The database may be corrupt or from an incompatible version.`);
|
|
2547
2547
|
}
|
|
2548
2548
|
function ji(e) {
|
|
2549
|
-
return
|
|
2549
|
+
return fn.every((t) => U(e, t));
|
|
2550
2550
|
}
|
|
2551
2551
|
function Mi(e) {
|
|
2552
2552
|
try {
|
|
@@ -2580,11 +2580,11 @@ function Ii(e, t) {
|
|
|
2580
2580
|
}
|
|
2581
2581
|
function Li(e) {
|
|
2582
2582
|
mi(e);
|
|
2583
|
-
let t =
|
|
2583
|
+
let t = F(e);
|
|
2584
2584
|
if (t === 0) throw Error("Database schema is not initialized. Initialize the SQLite database with the current TypeScript runtime before retrying.");
|
|
2585
2585
|
if (t < 6) throw Error(`Database schema version ${t} is older than minimum compatible (6). Upgrade the database schema with the current TypeScript runtime before retrying.`);
|
|
2586
2586
|
t > 26 && console.warn(`Database schema version ${t} is newer than this TS runtime (26). Running in compatibility mode — additive schema changes are tolerated.`);
|
|
2587
|
-
let n =
|
|
2587
|
+
let n = dn.filter((t) => !U(e, t));
|
|
2588
2588
|
if (n.length > 0) throw Error(`Required tables missing: ${n.join(", ")}. The database may be corrupt or from an incompatible version.`);
|
|
2589
2589
|
if (!U(e, "memory_fts")) throw Error("FTS5 index (memory_fts) is missing. Rebuild the database schema with the current TypeScript runtime before retrying.");
|
|
2590
2590
|
}
|
|
@@ -2604,7 +2604,7 @@ function G(e, t, n, r) {
|
|
|
2604
2604
|
}
|
|
2605
2605
|
var Ri = "recipient_policy_device_eligibility_schema_incompatible";
|
|
2606
2606
|
function zi(e) {
|
|
2607
|
-
!U(e, "identity_devices") || !W(e, "identity_devices", "identity_id") || !W(e, "identity_devices", "assignment_version") || !U(e, "policy_team_device_decisions") || !W(e, "policy_team_device_decisions", "device_id") ||
|
|
2607
|
+
!U(e, "identity_devices") || !W(e, "identity_devices", "identity_id") || !W(e, "identity_devices", "assignment_version") || !U(e, "policy_team_device_decisions") || !W(e, "policy_team_device_decisions", "device_id") || vn(e) || e.transaction(() => e.exec(gn)).immediate();
|
|
2608
2608
|
}
|
|
2609
2609
|
function Bi(e) {
|
|
2610
2610
|
e.exec("\n CREATE TABLE IF NOT EXISTS device_identity_binding_commits (\n commit_digest TEXT PRIMARY KEY NOT NULL,\n reviewed_inventory_digest TEXT NOT NULL,\n request_json TEXT NOT NULL,\n outcomes_json TEXT NOT NULL,\n write_count INTEGER NOT NULL,\n decided_by_identity_id TEXT NOT NULL,\n decided_by_device_id TEXT NOT NULL,\n created_at TEXT NOT NULL\n );\n CREATE TABLE IF NOT EXISTS device_identity_binding_audit (\n event_id TEXT PRIMARY KEY NOT NULL,\n commit_digest TEXT NOT NULL REFERENCES device_identity_binding_commits(commit_digest),\n device_id TEXT NOT NULL,\n previous_identity_id TEXT,\n target_identity_id TEXT NOT NULL,\n action TEXT NOT NULL,\n previous_assignment_version INTEGER,\n resulting_assignment_version INTEGER NOT NULL,\n decided_by_identity_id TEXT NOT NULL,\n decided_by_device_id TEXT NOT NULL,\n created_at TEXT NOT NULL\n );\n CREATE UNIQUE INDEX IF NOT EXISTS idx_device_identity_binding_audit_commit_device\n ON device_identity_binding_audit(commit_digest, device_id);\n CREATE INDEX IF NOT EXISTS idx_device_identity_binding_audit_device_created\n ON device_identity_binding_audit(device_id, created_at, event_id);\n ");
|
|
@@ -2747,7 +2747,7 @@ function ca(e) {
|
|
|
2747
2747
|
U(e, "recipient_policy_authority_states") && G(e, "recipient_policy_authority_states", "wake_epoch", "INTEGER NOT NULL DEFAULT 0");
|
|
2748
2748
|
}
|
|
2749
2749
|
function la(e) {
|
|
2750
|
-
if (
|
|
2750
|
+
if (Kn(e), Lr(e), ei(e), U(e, "sync_peers") && !W(e, "sync_peers", "manual_addresses_json")) try {
|
|
2751
2751
|
e.exec("ALTER TABLE sync_peers ADD COLUMN manual_addresses_json TEXT");
|
|
2752
2752
|
} catch (t) {
|
|
2753
2753
|
if (!W(e, "sync_peers", "manual_addresses_json")) throw t;
|
|
@@ -2757,16 +2757,16 @@ function la(e) {
|
|
|
2757
2757
|
} catch (t) {
|
|
2758
2758
|
if (!W(e, "sync_peers", "last_success_address")) throw t;
|
|
2759
2759
|
}
|
|
2760
|
-
|
|
2760
|
+
wn(e), oa(e);
|
|
2761
2761
|
try {
|
|
2762
2762
|
vr(e);
|
|
2763
2763
|
} catch {}
|
|
2764
2764
|
ca(e), qi(e), Ji(e), Yi(e), pi(e), ii(e), Bi(e), Gr(e), Vi(e), Hi(e), Ui(e), Wi(e);
|
|
2765
2765
|
}
|
|
2766
2766
|
function ua(e) {
|
|
2767
|
-
|
|
2767
|
+
On(e), la(e);
|
|
2768
2768
|
let t = Zi(e);
|
|
2769
|
-
_a(e, { compatAlreadyApplied: t }), V(e),
|
|
2769
|
+
_a(e, { compatAlreadyApplied: t }), V(e), L(e), ma(e), ha(e), Hn(e), Pn(e), kn(e), Br(e), Pr(e), jr(e), t || (ga(e), Qi(e)), da(e);
|
|
2770
2770
|
}
|
|
2771
2771
|
function da(e) {
|
|
2772
2772
|
try {
|
|
@@ -2826,7 +2826,7 @@ function ga(e) {
|
|
|
2826
2826
|
"recipient_policy_authority_states",
|
|
2827
2827
|
"recipient_policy_reconciliation_steps",
|
|
2828
2828
|
"recipient_policy_deny_overlays"
|
|
2829
|
-
].every((t) => U(e, t)), n =
|
|
2829
|
+
].every((t) => U(e, t)), n = F(e);
|
|
2830
2830
|
t && n > 0 && n < 26 && e.pragma("user_version = 26");
|
|
2831
2831
|
}
|
|
2832
2832
|
function _a(e, { compatAlreadyApplied: t }) {
|
|
@@ -3063,7 +3063,7 @@ function xa(e) {
|
|
|
3063
3063
|
}
|
|
3064
3064
|
//#endregion
|
|
3065
3065
|
//#region src/schema.ts
|
|
3066
|
-
var Sa = /* @__PURE__ */
|
|
3066
|
+
var Sa = /* @__PURE__ */ Te({
|
|
3067
3067
|
actors: () => oo,
|
|
3068
3068
|
artifacts: () => Ea,
|
|
3069
3069
|
attributionAssessmentEvidence: () => Na,
|
|
@@ -3125,835 +3125,835 @@ var Sa = /* @__PURE__ */ we({
|
|
|
3125
3125
|
syncScopeRejections: () => Za,
|
|
3126
3126
|
usageEvents: () => ka,
|
|
3127
3127
|
userPrompts: () => Ba
|
|
3128
|
-
}), K =
|
|
3129
|
-
id:
|
|
3130
|
-
started_at:
|
|
3131
|
-
ended_at:
|
|
3132
|
-
cwd:
|
|
3133
|
-
project:
|
|
3134
|
-
git_remote:
|
|
3135
|
-
git_branch:
|
|
3136
|
-
user:
|
|
3137
|
-
tool_version:
|
|
3138
|
-
metadata_json:
|
|
3139
|
-
import_key:
|
|
3140
|
-
}, (e) => [
|
|
3141
|
-
scope_id:
|
|
3142
|
-
label:
|
|
3143
|
-
kind:
|
|
3144
|
-
authority_type:
|
|
3145
|
-
coordinator_id:
|
|
3146
|
-
group_id:
|
|
3147
|
-
manifest_issuer_device_id:
|
|
3148
|
-
membership_epoch:
|
|
3149
|
-
manifest_hash:
|
|
3150
|
-
status:
|
|
3151
|
-
created_at:
|
|
3152
|
-
updated_at:
|
|
3153
|
-
}, (e) => [
|
|
3154
|
-
id:
|
|
3155
|
-
workspace_identity:
|
|
3156
|
-
project_pattern:
|
|
3157
|
-
scope_id:
|
|
3158
|
-
priority:
|
|
3159
|
-
source:
|
|
3160
|
-
created_at:
|
|
3161
|
-
updated_at:
|
|
3128
|
+
}), K = S("sessions", {
|
|
3129
|
+
id: b("id").primaryKey(),
|
|
3130
|
+
started_at: C("started_at").notNull(),
|
|
3131
|
+
ended_at: C("ended_at"),
|
|
3132
|
+
cwd: C("cwd"),
|
|
3133
|
+
project: C("project"),
|
|
3134
|
+
git_remote: C("git_remote"),
|
|
3135
|
+
git_branch: C("git_branch"),
|
|
3136
|
+
user: C("user"),
|
|
3137
|
+
tool_version: C("tool_version"),
|
|
3138
|
+
metadata_json: C("metadata_json"),
|
|
3139
|
+
import_key: C("import_key")
|
|
3140
|
+
}, (e) => [y("idx_sessions_started_id").on(e.started_at, e.id)]), Ca = S("replication_scopes", {
|
|
3141
|
+
scope_id: C("scope_id").primaryKey(),
|
|
3142
|
+
label: C("label").notNull(),
|
|
3143
|
+
kind: C("kind").notNull().default("user"),
|
|
3144
|
+
authority_type: C("authority_type").notNull().default("local"),
|
|
3145
|
+
coordinator_id: C("coordinator_id"),
|
|
3146
|
+
group_id: C("group_id"),
|
|
3147
|
+
manifest_issuer_device_id: C("manifest_issuer_device_id"),
|
|
3148
|
+
membership_epoch: b("membership_epoch").notNull().default(0),
|
|
3149
|
+
manifest_hash: C("manifest_hash"),
|
|
3150
|
+
status: C("status").notNull().default("active"),
|
|
3151
|
+
created_at: C("created_at").notNull(),
|
|
3152
|
+
updated_at: C("updated_at").notNull()
|
|
3153
|
+
}, (e) => [y("idx_replication_scopes_status").on(e.status), y("idx_replication_scopes_authority_group").on(e.coordinator_id, e.group_id)]), wa = S("project_scope_mappings", {
|
|
3154
|
+
id: b("id").primaryKey(),
|
|
3155
|
+
workspace_identity: C("workspace_identity"),
|
|
3156
|
+
project_pattern: C("project_pattern").notNull(),
|
|
3157
|
+
scope_id: C("scope_id").notNull(),
|
|
3158
|
+
priority: b("priority").notNull().default(0),
|
|
3159
|
+
source: C("source").notNull().default("user"),
|
|
3160
|
+
created_at: C("created_at").notNull(),
|
|
3161
|
+
updated_at: C("updated_at").notNull()
|
|
3162
3162
|
}, (e) => [
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
]), Ta =
|
|
3167
|
-
scope_id:
|
|
3168
|
-
device_id:
|
|
3169
|
-
role:
|
|
3170
|
-
status:
|
|
3171
|
-
membership_epoch:
|
|
3172
|
-
coordinator_id:
|
|
3173
|
-
group_id:
|
|
3174
|
-
manifest_issuer_device_id:
|
|
3175
|
-
manifest_hash:
|
|
3176
|
-
signed_manifest_json:
|
|
3177
|
-
updated_at:
|
|
3163
|
+
y("idx_project_scope_mappings_workspace_priority").on(e.workspace_identity, e.priority),
|
|
3164
|
+
y("idx_project_scope_mappings_pattern_priority").on(e.project_pattern, e.priority),
|
|
3165
|
+
y("idx_project_scope_mappings_scope").on(e.scope_id)
|
|
3166
|
+
]), Ta = S("scope_memberships", {
|
|
3167
|
+
scope_id: C("scope_id").notNull(),
|
|
3168
|
+
device_id: C("device_id").notNull(),
|
|
3169
|
+
role: C("role").notNull().default("member"),
|
|
3170
|
+
status: C("status").notNull().default("active"),
|
|
3171
|
+
membership_epoch: b("membership_epoch").notNull().default(0),
|
|
3172
|
+
coordinator_id: C("coordinator_id"),
|
|
3173
|
+
group_id: C("group_id"),
|
|
3174
|
+
manifest_issuer_device_id: C("manifest_issuer_device_id"),
|
|
3175
|
+
manifest_hash: C("manifest_hash"),
|
|
3176
|
+
signed_manifest_json: C("signed_manifest_json"),
|
|
3177
|
+
updated_at: C("updated_at").notNull()
|
|
3178
3178
|
}, (e) => [
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
]), Ea =
|
|
3184
|
-
id:
|
|
3185
|
-
session_id:
|
|
3186
|
-
kind:
|
|
3187
|
-
path:
|
|
3188
|
-
content_text:
|
|
3189
|
-
content_hash:
|
|
3190
|
-
created_at:
|
|
3191
|
-
metadata_json:
|
|
3192
|
-
}, (e) => [
|
|
3193
|
-
id:
|
|
3194
|
-
session_id:
|
|
3195
|
-
kind:
|
|
3196
|
-
title:
|
|
3197
|
-
subtitle:
|
|
3198
|
-
body_text:
|
|
3199
|
-
confidence:
|
|
3200
|
-
tags_text:
|
|
3201
|
-
active:
|
|
3202
|
-
created_at:
|
|
3203
|
-
updated_at:
|
|
3204
|
-
metadata_json:
|
|
3205
|
-
actor_id:
|
|
3206
|
-
actor_display_name:
|
|
3207
|
-
visibility:
|
|
3208
|
-
workspace_id:
|
|
3209
|
-
workspace_kind:
|
|
3210
|
-
origin_device_id:
|
|
3211
|
-
origin_source:
|
|
3212
|
-
trust_state:
|
|
3213
|
-
facts:
|
|
3214
|
-
narrative:
|
|
3215
|
-
concepts:
|
|
3216
|
-
files_read:
|
|
3217
|
-
files_modified:
|
|
3218
|
-
user_prompt_id:
|
|
3219
|
-
prompt_number:
|
|
3220
|
-
deleted_at:
|
|
3221
|
-
rev:
|
|
3222
|
-
dedup_key:
|
|
3223
|
-
import_key:
|
|
3224
|
-
scope_id:
|
|
3225
|
-
project:
|
|
3179
|
+
x({ columns: [e.scope_id, e.device_id] }),
|
|
3180
|
+
y("idx_scope_memberships_device_status").on(e.device_id, e.status),
|
|
3181
|
+
y("idx_scope_memberships_scope_status").on(e.scope_id, e.status),
|
|
3182
|
+
y("idx_scope_memberships_authority_group").on(e.coordinator_id, e.group_id)
|
|
3183
|
+
]), Ea = S("artifacts", {
|
|
3184
|
+
id: b("id").primaryKey(),
|
|
3185
|
+
session_id: b("session_id").notNull().references(() => K.id, { onDelete: "cascade" }),
|
|
3186
|
+
kind: C("kind").notNull(),
|
|
3187
|
+
path: C("path"),
|
|
3188
|
+
content_text: C("content_text"),
|
|
3189
|
+
content_hash: C("content_hash"),
|
|
3190
|
+
created_at: C("created_at").notNull(),
|
|
3191
|
+
metadata_json: C("metadata_json")
|
|
3192
|
+
}, (e) => [y("idx_artifacts_session_kind").on(e.session_id, e.kind)]), q = S("memory_items", {
|
|
3193
|
+
id: b("id").primaryKey(),
|
|
3194
|
+
session_id: b("session_id").notNull().references(() => K.id, { onDelete: "cascade" }),
|
|
3195
|
+
kind: C("kind").notNull(),
|
|
3196
|
+
title: C("title").notNull(),
|
|
3197
|
+
subtitle: C("subtitle"),
|
|
3198
|
+
body_text: C("body_text").notNull(),
|
|
3199
|
+
confidence: Ce("confidence").default(.5),
|
|
3200
|
+
tags_text: C("tags_text").default(""),
|
|
3201
|
+
active: b("active").default(1),
|
|
3202
|
+
created_at: C("created_at").notNull(),
|
|
3203
|
+
updated_at: C("updated_at").notNull(),
|
|
3204
|
+
metadata_json: C("metadata_json"),
|
|
3205
|
+
actor_id: C("actor_id"),
|
|
3206
|
+
actor_display_name: C("actor_display_name"),
|
|
3207
|
+
visibility: C("visibility"),
|
|
3208
|
+
workspace_id: C("workspace_id"),
|
|
3209
|
+
workspace_kind: C("workspace_kind"),
|
|
3210
|
+
origin_device_id: C("origin_device_id"),
|
|
3211
|
+
origin_source: C("origin_source"),
|
|
3212
|
+
trust_state: C("trust_state"),
|
|
3213
|
+
facts: C("facts"),
|
|
3214
|
+
narrative: C("narrative"),
|
|
3215
|
+
concepts: C("concepts"),
|
|
3216
|
+
files_read: C("files_read"),
|
|
3217
|
+
files_modified: C("files_modified"),
|
|
3218
|
+
user_prompt_id: b("user_prompt_id"),
|
|
3219
|
+
prompt_number: b("prompt_number"),
|
|
3220
|
+
deleted_at: C("deleted_at"),
|
|
3221
|
+
rev: b("rev").default(0),
|
|
3222
|
+
dedup_key: C("dedup_key"),
|
|
3223
|
+
import_key: C("import_key"),
|
|
3224
|
+
scope_id: C("scope_id"),
|
|
3225
|
+
project: C("project")
|
|
3226
3226
|
}, (e) => [
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
]), Da =
|
|
3237
|
-
memory_id:
|
|
3238
|
-
file_path:
|
|
3239
|
-
relation:
|
|
3240
|
-
}, (e) => [
|
|
3227
|
+
y("idx_memory_items_active_created").on(e.active, e.created_at),
|
|
3228
|
+
y("idx_memory_items_created_id").on(e.created_at, e.id),
|
|
3229
|
+
y("idx_memory_items_origin_device_active").on(e.origin_device_id, e.active),
|
|
3230
|
+
y("idx_memory_items_session").on(e.session_id),
|
|
3231
|
+
y("idx_memory_items_project").on(e.project),
|
|
3232
|
+
y("idx_memory_items_scope_visibility_created").on(e.scope_id, e.visibility, e.created_at),
|
|
3233
|
+
y("idx_memory_items_scope_backfill_pending").on(e.id).where(v`scope_id IS NULL OR scope_id = ''`),
|
|
3234
|
+
y("idx_memory_items_dedup_key_active_created").on(e.dedup_key, e.active, e.created_at),
|
|
3235
|
+
w("idx_memory_items_same_session_dedup_unique").on(e.session_id, e.kind, e.visibility, e.workspace_id, e.dedup_key).where(v`active = 1 AND dedup_key IS NOT NULL`)
|
|
3236
|
+
]), Da = S("memory_file_refs", {
|
|
3237
|
+
memory_id: b("memory_id").notNull().references(() => q.id, { onDelete: "cascade" }),
|
|
3238
|
+
file_path: C("file_path").notNull(),
|
|
3239
|
+
relation: C("relation").notNull()
|
|
3240
|
+
}, (e) => [x({ columns: [
|
|
3241
3241
|
e.memory_id,
|
|
3242
3242
|
e.file_path,
|
|
3243
3243
|
e.relation
|
|
3244
|
-
] }),
|
|
3245
|
-
memory_id:
|
|
3246
|
-
concept:
|
|
3247
|
-
}, (e) => [
|
|
3248
|
-
id:
|
|
3249
|
-
session_id:
|
|
3250
|
-
event:
|
|
3251
|
-
tokens_read:
|
|
3252
|
-
tokens_written:
|
|
3253
|
-
tokens_saved:
|
|
3254
|
-
created_at:
|
|
3255
|
-
metadata_json:
|
|
3256
|
-
}, (e) => [
|
|
3257
|
-
attempt_id:
|
|
3258
|
-
contract_version:
|
|
3259
|
-
surface:
|
|
3260
|
-
trigger:
|
|
3261
|
-
started_at:
|
|
3262
|
-
completed_at:
|
|
3263
|
-
retrieval_status:
|
|
3264
|
-
delivery_status:
|
|
3265
|
-
candidate_count:
|
|
3266
|
-
selected_count:
|
|
3267
|
-
persisted_candidate_count:
|
|
3268
|
-
recorder_version:
|
|
3269
|
-
session_id:
|
|
3270
|
-
source:
|
|
3271
|
-
stream_id:
|
|
3272
|
-
source_session_id:
|
|
3273
|
-
prompt_number:
|
|
3274
|
-
request_id:
|
|
3275
|
-
raw_event_start_seq:
|
|
3276
|
-
raw_event_end_seq:
|
|
3277
|
-
experiment_id:
|
|
3278
|
-
experiment_cell_id:
|
|
3279
|
-
evaluation_checkout_id:
|
|
3280
|
-
evaluation_fixture_id:
|
|
3281
|
-
evaluation_seed:
|
|
3282
|
-
latency_ms:
|
|
3283
|
-
project:
|
|
3284
|
-
scope_id:
|
|
3285
|
-
mode:
|
|
3286
|
-
limit_requested:
|
|
3287
|
-
token_budget:
|
|
3288
|
-
output_tokens:
|
|
3289
|
-
working_set_file_count:
|
|
3290
|
-
working_set_files_json:
|
|
3291
|
-
query_hash_sha256:
|
|
3292
|
-
query_char_count:
|
|
3293
|
-
query_token_estimate:
|
|
3294
|
-
filter_summary_json:
|
|
3295
|
-
failure_code:
|
|
3296
|
-
failure_stage:
|
|
3297
|
-
trace_version:
|
|
3298
|
-
automatic_recall_json:
|
|
3299
|
-
automatic_recall_key:
|
|
3300
|
-
retention_until:
|
|
3301
|
-
retention_pinned:
|
|
3302
|
-
retention_finalized_at:
|
|
3244
|
+
] }), y("idx_memory_file_refs_path").on(e.file_path)]), Oa = S("memory_concept_refs", {
|
|
3245
|
+
memory_id: b("memory_id").notNull().references(() => q.id, { onDelete: "cascade" }),
|
|
3246
|
+
concept: C("concept").notNull()
|
|
3247
|
+
}, (e) => [x({ columns: [e.memory_id, e.concept] }), y("idx_memory_concept_refs_concept").on(e.concept)]), ka = S("usage_events", {
|
|
3248
|
+
id: b("id").primaryKey(),
|
|
3249
|
+
session_id: b("session_id").references(() => K.id, { onDelete: "set null" }),
|
|
3250
|
+
event: C("event").notNull(),
|
|
3251
|
+
tokens_read: b("tokens_read").default(0),
|
|
3252
|
+
tokens_written: b("tokens_written").default(0),
|
|
3253
|
+
tokens_saved: b("tokens_saved").default(0),
|
|
3254
|
+
created_at: C("created_at").notNull(),
|
|
3255
|
+
metadata_json: C("metadata_json")
|
|
3256
|
+
}, (e) => [y("idx_usage_events_event_created").on(e.event, e.created_at), y("idx_usage_events_session").on(e.session_id)]), J = S("retrieval_attempts", {
|
|
3257
|
+
attempt_id: C("attempt_id").primaryKey(),
|
|
3258
|
+
contract_version: b("contract_version").notNull(),
|
|
3259
|
+
surface: C("surface").notNull(),
|
|
3260
|
+
trigger: C("trigger").notNull(),
|
|
3261
|
+
started_at: C("started_at").notNull(),
|
|
3262
|
+
completed_at: C("completed_at"),
|
|
3263
|
+
retrieval_status: C("retrieval_status").notNull(),
|
|
3264
|
+
delivery_status: C("delivery_status").notNull(),
|
|
3265
|
+
candidate_count: b("candidate_count").notNull(),
|
|
3266
|
+
selected_count: b("selected_count").notNull(),
|
|
3267
|
+
persisted_candidate_count: b("persisted_candidate_count").notNull(),
|
|
3268
|
+
recorder_version: C("recorder_version").notNull(),
|
|
3269
|
+
session_id: b("session_id").references(() => K.id, { onDelete: "cascade" }),
|
|
3270
|
+
source: C("source"),
|
|
3271
|
+
stream_id: C("stream_id"),
|
|
3272
|
+
source_session_id: C("source_session_id"),
|
|
3273
|
+
prompt_number: b("prompt_number"),
|
|
3274
|
+
request_id: C("request_id"),
|
|
3275
|
+
raw_event_start_seq: b("raw_event_start_seq"),
|
|
3276
|
+
raw_event_end_seq: b("raw_event_end_seq"),
|
|
3277
|
+
experiment_id: C("experiment_id"),
|
|
3278
|
+
experiment_cell_id: C("experiment_cell_id"),
|
|
3279
|
+
evaluation_checkout_id: C("evaluation_checkout_id"),
|
|
3280
|
+
evaluation_fixture_id: C("evaluation_fixture_id"),
|
|
3281
|
+
evaluation_seed: b("evaluation_seed"),
|
|
3282
|
+
latency_ms: b("latency_ms"),
|
|
3283
|
+
project: C("project"),
|
|
3284
|
+
scope_id: C("scope_id"),
|
|
3285
|
+
mode: C("mode"),
|
|
3286
|
+
limit_requested: b("limit_requested"),
|
|
3287
|
+
token_budget: b("token_budget"),
|
|
3288
|
+
output_tokens: b("output_tokens"),
|
|
3289
|
+
working_set_file_count: b("working_set_file_count"),
|
|
3290
|
+
working_set_files_json: C("working_set_files_json"),
|
|
3291
|
+
query_hash_sha256: C("query_hash_sha256"),
|
|
3292
|
+
query_char_count: b("query_char_count"),
|
|
3293
|
+
query_token_estimate: b("query_token_estimate"),
|
|
3294
|
+
filter_summary_json: C("filter_summary_json"),
|
|
3295
|
+
failure_code: C("failure_code"),
|
|
3296
|
+
failure_stage: C("failure_stage"),
|
|
3297
|
+
trace_version: b("trace_version"),
|
|
3298
|
+
automatic_recall_json: C("automatic_recall_json"),
|
|
3299
|
+
automatic_recall_key: C("automatic_recall_key"),
|
|
3300
|
+
retention_until: C("retention_until"),
|
|
3301
|
+
retention_pinned: b("retention_pinned").notNull().default(0),
|
|
3302
|
+
retention_finalized_at: C("retention_finalized_at")
|
|
3303
3303
|
}, (e) => [
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
]), Aa =
|
|
3313
|
-
exposure_id:
|
|
3314
|
-
attempt_id:
|
|
3315
|
-
memory_id:
|
|
3316
|
-
memory_import_key:
|
|
3317
|
-
origin_device_id:
|
|
3318
|
-
rank:
|
|
3319
|
-
disposition:
|
|
3320
|
-
section:
|
|
3321
|
-
handoff_status:
|
|
3322
|
-
memory_rev:
|
|
3323
|
-
memory_updated_at:
|
|
3324
|
-
memory_scope_id:
|
|
3325
|
-
memory_kind:
|
|
3326
|
-
memory_active:
|
|
3327
|
-
memory_deleted_at:
|
|
3328
|
-
score_summary_json:
|
|
3329
|
-
reason_codes_json:
|
|
3330
|
-
}, (e) => [
|
|
3331
|
-
evidence_id:
|
|
3332
|
-
contract_version:
|
|
3333
|
-
dimension:
|
|
3334
|
-
evidence_type:
|
|
3335
|
-
source_class:
|
|
3336
|
-
observed_at:
|
|
3337
|
-
producer:
|
|
3338
|
-
producer_version:
|
|
3339
|
-
status:
|
|
3340
|
-
value_type:
|
|
3341
|
-
value_integer:
|
|
3342
|
-
value_real:
|
|
3343
|
-
value_unit:
|
|
3344
|
-
session_id:
|
|
3345
|
-
source:
|
|
3346
|
-
stream_id:
|
|
3347
|
-
source_session_id:
|
|
3348
|
-
prompt_number:
|
|
3349
|
-
raw_event_start_seq:
|
|
3350
|
-
raw_event_end_seq:
|
|
3351
|
-
experiment_id:
|
|
3352
|
-
experiment_cell_id:
|
|
3353
|
-
window_start_at:
|
|
3354
|
-
window_end_at:
|
|
3355
|
-
references_json:
|
|
3356
|
-
retention_until:
|
|
3357
|
-
retention_pinned:
|
|
3358
|
-
retention_finalized_at:
|
|
3304
|
+
y("idx_retrieval_attempts_session_started").on(e.session_id, e.started_at),
|
|
3305
|
+
w("idx_retrieval_attempts_automatic_recall_key").on(e.automatic_recall_key),
|
|
3306
|
+
y("idx_retrieval_attempts_source_stream_started").on(e.source, e.stream_id, e.started_at),
|
|
3307
|
+
y("idx_retrieval_attempts_retention").on(e.retention_pinned, e.retention_until),
|
|
3308
|
+
y("idx_retrieval_attempts_started").on(e.started_at, e.attempt_id),
|
|
3309
|
+
y("idx_retrieval_attempts_surface_started").on(e.surface, e.started_at),
|
|
3310
|
+
w("idx_retrieval_attempts_request_identity").on(e.source, e.surface, e.request_id).where(v`request_id IS NOT NULL`),
|
|
3311
|
+
y("idx_retrieval_attempts_experiment_cell").on(e.experiment_id, e.experiment_cell_id)
|
|
3312
|
+
]), Aa = S("retrieval_exposures", {
|
|
3313
|
+
exposure_id: b("exposure_id").primaryKey({ autoIncrement: !0 }),
|
|
3314
|
+
attempt_id: C("attempt_id").notNull().references(() => J.attempt_id, { onDelete: "cascade" }),
|
|
3315
|
+
memory_id: b("memory_id").references(() => q.id, { onDelete: "set null" }),
|
|
3316
|
+
memory_import_key: C("memory_import_key"),
|
|
3317
|
+
origin_device_id: C("origin_device_id"),
|
|
3318
|
+
rank: b("rank").notNull(),
|
|
3319
|
+
disposition: C("disposition").notNull(),
|
|
3320
|
+
section: C("section"),
|
|
3321
|
+
handoff_status: C("handoff_status").notNull(),
|
|
3322
|
+
memory_rev: b("memory_rev"),
|
|
3323
|
+
memory_updated_at: C("memory_updated_at"),
|
|
3324
|
+
memory_scope_id: C("memory_scope_id"),
|
|
3325
|
+
memory_kind: C("memory_kind"),
|
|
3326
|
+
memory_active: b("memory_active"),
|
|
3327
|
+
memory_deleted_at: C("memory_deleted_at"),
|
|
3328
|
+
score_summary_json: C("score_summary_json"),
|
|
3329
|
+
reason_codes_json: C("reason_codes_json")
|
|
3330
|
+
}, (e) => [w("idx_retrieval_exposures_attempt_rank").on(e.attempt_id, e.rank), y("idx_retrieval_exposures_memory").on(e.memory_id)]), ja = S("outcome_evidence", {
|
|
3331
|
+
evidence_id: C("evidence_id").primaryKey(),
|
|
3332
|
+
contract_version: b("contract_version").notNull(),
|
|
3333
|
+
dimension: C("dimension").notNull(),
|
|
3334
|
+
evidence_type: C("evidence_type").notNull(),
|
|
3335
|
+
source_class: C("source_class").notNull(),
|
|
3336
|
+
observed_at: C("observed_at").notNull(),
|
|
3337
|
+
producer: C("producer").notNull(),
|
|
3338
|
+
producer_version: C("producer_version").notNull(),
|
|
3339
|
+
status: C("status").notNull(),
|
|
3340
|
+
value_type: C("value_type"),
|
|
3341
|
+
value_integer: b("value_integer"),
|
|
3342
|
+
value_real: Ce("value_real"),
|
|
3343
|
+
value_unit: C("value_unit"),
|
|
3344
|
+
session_id: b("session_id").references(() => K.id, { onDelete: "cascade" }),
|
|
3345
|
+
source: C("source"),
|
|
3346
|
+
stream_id: C("stream_id"),
|
|
3347
|
+
source_session_id: C("source_session_id"),
|
|
3348
|
+
prompt_number: b("prompt_number"),
|
|
3349
|
+
raw_event_start_seq: b("raw_event_start_seq"),
|
|
3350
|
+
raw_event_end_seq: b("raw_event_end_seq"),
|
|
3351
|
+
experiment_id: C("experiment_id"),
|
|
3352
|
+
experiment_cell_id: C("experiment_cell_id"),
|
|
3353
|
+
window_start_at: C("window_start_at"),
|
|
3354
|
+
window_end_at: C("window_end_at"),
|
|
3355
|
+
references_json: C("references_json"),
|
|
3356
|
+
retention_until: C("retention_until"),
|
|
3357
|
+
retention_pinned: b("retention_pinned").notNull().default(0),
|
|
3358
|
+
retention_finalized_at: C("retention_finalized_at")
|
|
3359
3359
|
}, (e) => [
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
]), Ma =
|
|
3366
|
-
assessment_id:
|
|
3367
|
-
contract_version:
|
|
3368
|
-
subject_type:
|
|
3369
|
-
attempt_id:
|
|
3370
|
-
exposure_id:
|
|
3371
|
-
dimension:
|
|
3372
|
-
impact_label:
|
|
3373
|
-
basis:
|
|
3374
|
-
confidence_level:
|
|
3375
|
-
method:
|
|
3376
|
-
method_version:
|
|
3377
|
-
created_at:
|
|
3378
|
-
claim_type:
|
|
3360
|
+
y("idx_outcome_evidence_observed_id").on(e.observed_at, e.evidence_id),
|
|
3361
|
+
y("idx_outcome_evidence_session_observed").on(e.session_id, e.observed_at),
|
|
3362
|
+
y("idx_outcome_evidence_source_stream_observed").on(e.source, e.stream_id, e.observed_at),
|
|
3363
|
+
y("idx_outcome_evidence_type_observed").on(e.evidence_type, e.observed_at),
|
|
3364
|
+
y("idx_outcome_evidence_retention").on(e.retention_pinned, e.retention_until)
|
|
3365
|
+
]), Ma = S("attribution_assessments", {
|
|
3366
|
+
assessment_id: C("assessment_id").primaryKey(),
|
|
3367
|
+
contract_version: b("contract_version").notNull(),
|
|
3368
|
+
subject_type: C("subject_type").notNull(),
|
|
3369
|
+
attempt_id: C("attempt_id").notNull().references(() => J.attempt_id, { onDelete: "cascade" }),
|
|
3370
|
+
exposure_id: b("exposure_id").references(() => Aa.exposure_id, { onDelete: "cascade" }),
|
|
3371
|
+
dimension: C("dimension").notNull(),
|
|
3372
|
+
impact_label: C("impact_label").notNull(),
|
|
3373
|
+
basis: C("basis").notNull(),
|
|
3374
|
+
confidence_level: C("confidence_level").notNull(),
|
|
3375
|
+
method: C("method").notNull(),
|
|
3376
|
+
method_version: C("method_version").notNull(),
|
|
3377
|
+
created_at: C("created_at").notNull(),
|
|
3378
|
+
claim_type: C("claim_type").notNull().default("observational")
|
|
3379
3379
|
}, (e) => [
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
]), Na =
|
|
3384
|
-
assessment_id:
|
|
3385
|
-
evidence_id:
|
|
3386
|
-
}, (e) => [
|
|
3387
|
-
kind:
|
|
3388
|
-
title:
|
|
3389
|
-
status:
|
|
3390
|
-
message:
|
|
3391
|
-
progress_current:
|
|
3392
|
-
progress_total:
|
|
3393
|
-
progress_unit:
|
|
3394
|
-
metadata_json:
|
|
3395
|
-
started_at:
|
|
3396
|
-
updated_at:
|
|
3397
|
-
finished_at:
|
|
3398
|
-
error:
|
|
3399
|
-
}, (e) => [
|
|
3400
|
-
id:
|
|
3401
|
-
source:
|
|
3402
|
-
stream_id:
|
|
3403
|
-
opencode_session_id:
|
|
3404
|
-
event_id:
|
|
3405
|
-
event_seq:
|
|
3406
|
-
event_type:
|
|
3407
|
-
ts_wall_ms:
|
|
3408
|
-
ts_mono_ms:
|
|
3409
|
-
payload_json:
|
|
3410
|
-
capture_context_json:
|
|
3411
|
-
created_at:
|
|
3380
|
+
y("idx_attribution_assessments_attempt_created").on(e.attempt_id, e.created_at),
|
|
3381
|
+
y("idx_attribution_assessments_label_created").on(e.impact_label, e.created_at),
|
|
3382
|
+
y("idx_attribution_assessments_exposure").on(e.exposure_id)
|
|
3383
|
+
]), Na = S("attribution_assessment_evidence", {
|
|
3384
|
+
assessment_id: C("assessment_id").notNull().references(() => Ma.assessment_id, { onDelete: "cascade" }),
|
|
3385
|
+
evidence_id: C("evidence_id").notNull().references(() => ja.evidence_id, { onDelete: "cascade" })
|
|
3386
|
+
}, (e) => [x({ columns: [e.assessment_id, e.evidence_id] }), y("idx_attribution_assessment_evidence_evidence").on(e.evidence_id, e.assessment_id)]), Pa = S("maintenance_jobs", {
|
|
3387
|
+
kind: C("kind").primaryKey(),
|
|
3388
|
+
title: C("title").notNull(),
|
|
3389
|
+
status: C("status").notNull(),
|
|
3390
|
+
message: C("message"),
|
|
3391
|
+
progress_current: b("progress_current").notNull().default(0),
|
|
3392
|
+
progress_total: b("progress_total"),
|
|
3393
|
+
progress_unit: C("progress_unit").notNull().default("items"),
|
|
3394
|
+
metadata_json: C("metadata_json"),
|
|
3395
|
+
started_at: C("started_at"),
|
|
3396
|
+
updated_at: C("updated_at").notNull(),
|
|
3397
|
+
finished_at: C("finished_at"),
|
|
3398
|
+
error: C("error")
|
|
3399
|
+
}, (e) => [y("idx_maintenance_jobs_status_updated").on(e.status, e.updated_at)]), Fa = S("raw_events", {
|
|
3400
|
+
id: b("id").primaryKey(),
|
|
3401
|
+
source: C("source").notNull().default("opencode"),
|
|
3402
|
+
stream_id: C("stream_id").notNull().default(""),
|
|
3403
|
+
opencode_session_id: C("opencode_session_id").notNull(),
|
|
3404
|
+
event_id: C("event_id"),
|
|
3405
|
+
event_seq: b("event_seq").notNull(),
|
|
3406
|
+
event_type: C("event_type").notNull(),
|
|
3407
|
+
ts_wall_ms: b("ts_wall_ms"),
|
|
3408
|
+
ts_mono_ms: Ce("ts_mono_ms"),
|
|
3409
|
+
payload_json: C("payload_json").notNull(),
|
|
3410
|
+
capture_context_json: C("capture_context_json"),
|
|
3411
|
+
created_at: C("created_at").notNull()
|
|
3412
3412
|
}, (e) => [
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
]), Ia =
|
|
3419
|
-
source:
|
|
3420
|
-
stream_id:
|
|
3421
|
-
opencode_session_id:
|
|
3422
|
-
cwd:
|
|
3423
|
-
project:
|
|
3424
|
-
started_at:
|
|
3425
|
-
last_seen_ts_wall_ms:
|
|
3426
|
-
last_received_event_seq:
|
|
3427
|
-
last_flushed_event_seq:
|
|
3428
|
-
updated_at:
|
|
3429
|
-
}, (e) => [
|
|
3430
|
-
file_path:
|
|
3431
|
-
size_bytes:
|
|
3432
|
-
mtime_ms:
|
|
3433
|
-
updated_at:
|
|
3434
|
-
}), Ra =
|
|
3435
|
-
source:
|
|
3436
|
-
stream_id:
|
|
3437
|
-
opencode_session_id:
|
|
3438
|
-
session_id:
|
|
3439
|
-
created_at:
|
|
3440
|
-
}, (e) => [
|
|
3441
|
-
id:
|
|
3442
|
-
source:
|
|
3443
|
-
stream_id:
|
|
3444
|
-
opencode_session_id:
|
|
3445
|
-
start_event_seq:
|
|
3446
|
-
end_event_seq:
|
|
3447
|
-
extractor_version:
|
|
3448
|
-
status:
|
|
3449
|
-
error_message:
|
|
3450
|
-
error_type:
|
|
3451
|
-
observer_provider:
|
|
3452
|
-
observer_model:
|
|
3453
|
-
observer_runtime:
|
|
3454
|
-
observer_auth_source:
|
|
3455
|
-
observer_auth_type:
|
|
3456
|
-
observer_error_code:
|
|
3457
|
-
observer_error_message:
|
|
3458
|
-
attempt_count:
|
|
3459
|
-
claim_generation:
|
|
3460
|
-
created_at:
|
|
3461
|
-
updated_at:
|
|
3413
|
+
w("idx_raw_events_source_stream_seq").on(e.source, e.stream_id, e.event_seq),
|
|
3414
|
+
w("idx_raw_events_source_stream_event_id").on(e.source, e.stream_id, e.event_id),
|
|
3415
|
+
y("idx_raw_events_session_seq").on(e.opencode_session_id, e.event_seq),
|
|
3416
|
+
y("idx_raw_events_created").on(e.created_at),
|
|
3417
|
+
y("idx_raw_events_capture_context").on(e.source, e.stream_id, e.event_seq).where(v`${e.capture_context_json} IS NOT NULL`)
|
|
3418
|
+
]), Ia = S("raw_event_sessions", {
|
|
3419
|
+
source: C("source").notNull().default("opencode"),
|
|
3420
|
+
stream_id: C("stream_id").notNull().default(""),
|
|
3421
|
+
opencode_session_id: C("opencode_session_id").notNull(),
|
|
3422
|
+
cwd: C("cwd"),
|
|
3423
|
+
project: C("project"),
|
|
3424
|
+
started_at: C("started_at"),
|
|
3425
|
+
last_seen_ts_wall_ms: b("last_seen_ts_wall_ms"),
|
|
3426
|
+
last_received_event_seq: b("last_received_event_seq").notNull().default(-1),
|
|
3427
|
+
last_flushed_event_seq: b("last_flushed_event_seq").notNull().default(-1),
|
|
3428
|
+
updated_at: C("updated_at").notNull()
|
|
3429
|
+
}, (e) => [x({ columns: [e.source, e.stream_id] }), y("idx_raw_event_sessions_pending_updated").on(e.updated_at).where(v`${e.last_received_event_seq} > ${e.last_flushed_event_seq}`)]), La = S("pi_import_state", {
|
|
3430
|
+
file_path: C("file_path").primaryKey(),
|
|
3431
|
+
size_bytes: b("size_bytes").notNull(),
|
|
3432
|
+
mtime_ms: Ce("mtime_ms").notNull(),
|
|
3433
|
+
updated_at: C("updated_at").notNull()
|
|
3434
|
+
}), Ra = S("opencode_sessions", {
|
|
3435
|
+
source: C("source").notNull().default("opencode"),
|
|
3436
|
+
stream_id: C("stream_id").notNull().default(""),
|
|
3437
|
+
opencode_session_id: C("opencode_session_id").notNull(),
|
|
3438
|
+
session_id: b("session_id").references(() => K.id, { onDelete: "cascade" }),
|
|
3439
|
+
created_at: C("created_at").notNull()
|
|
3440
|
+
}, (e) => [x({ columns: [e.source, e.stream_id] }), y("idx_opencode_sessions_session").on(e.session_id)]), za = S("raw_event_flush_batches", {
|
|
3441
|
+
id: b("id").primaryKey(),
|
|
3442
|
+
source: C("source").notNull().default("opencode"),
|
|
3443
|
+
stream_id: C("stream_id").notNull().default(""),
|
|
3444
|
+
opencode_session_id: C("opencode_session_id").notNull(),
|
|
3445
|
+
start_event_seq: b("start_event_seq").notNull(),
|
|
3446
|
+
end_event_seq: b("end_event_seq").notNull(),
|
|
3447
|
+
extractor_version: C("extractor_version").notNull(),
|
|
3448
|
+
status: C("status").notNull(),
|
|
3449
|
+
error_message: C("error_message"),
|
|
3450
|
+
error_type: C("error_type"),
|
|
3451
|
+
observer_provider: C("observer_provider"),
|
|
3452
|
+
observer_model: C("observer_model"),
|
|
3453
|
+
observer_runtime: C("observer_runtime"),
|
|
3454
|
+
observer_auth_source: C("observer_auth_source"),
|
|
3455
|
+
observer_auth_type: C("observer_auth_type"),
|
|
3456
|
+
observer_error_code: C("observer_error_code"),
|
|
3457
|
+
observer_error_message: C("observer_error_message"),
|
|
3458
|
+
attempt_count: b("attempt_count").notNull().default(0),
|
|
3459
|
+
claim_generation: b("claim_generation").notNull().default(0),
|
|
3460
|
+
created_at: C("created_at").notNull(),
|
|
3461
|
+
updated_at: C("updated_at").notNull()
|
|
3462
3462
|
}, (e) => [
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
]), Ba =
|
|
3469
|
-
id:
|
|
3470
|
-
session_id:
|
|
3471
|
-
project:
|
|
3472
|
-
prompt_text:
|
|
3473
|
-
prompt_number:
|
|
3474
|
-
created_at:
|
|
3475
|
-
created_at_epoch:
|
|
3476
|
-
metadata_json:
|
|
3477
|
-
import_key:
|
|
3463
|
+
w("idx_flush_batches_source_stream_seq_ver").on(e.source, e.stream_id, e.start_event_seq, e.end_event_seq, e.extractor_version),
|
|
3464
|
+
y("idx_flush_batches_session_created").on(e.opencode_session_id, e.created_at),
|
|
3465
|
+
y("idx_flush_batches_status_updated").on(e.status, e.updated_at),
|
|
3466
|
+
y("idx_flush_batches_observer_status_updated").on(e.status, e.updated_at).where(v`${e.observer_provider} IS NOT NULL`),
|
|
3467
|
+
y("idx_flush_batches_capture_status_updated").on(e.status, e.updated_at).where(v`${e.observer_provider} IS NULL`)
|
|
3468
|
+
]), Ba = S("user_prompts", {
|
|
3469
|
+
id: b("id").primaryKey(),
|
|
3470
|
+
session_id: b("session_id").references(() => K.id, { onDelete: "cascade" }),
|
|
3471
|
+
project: C("project"),
|
|
3472
|
+
prompt_text: C("prompt_text").notNull(),
|
|
3473
|
+
prompt_number: b("prompt_number"),
|
|
3474
|
+
created_at: C("created_at").notNull(),
|
|
3475
|
+
created_at_epoch: b("created_at_epoch").notNull(),
|
|
3476
|
+
metadata_json: C("metadata_json"),
|
|
3477
|
+
import_key: C("import_key")
|
|
3478
3478
|
}, (e) => [
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
]), Va =
|
|
3483
|
-
id:
|
|
3484
|
-
session_id:
|
|
3485
|
-
project:
|
|
3486
|
-
request:
|
|
3487
|
-
investigated:
|
|
3488
|
-
learned:
|
|
3489
|
-
completed:
|
|
3490
|
-
next_steps:
|
|
3491
|
-
notes:
|
|
3492
|
-
files_read:
|
|
3493
|
-
files_edited:
|
|
3494
|
-
prompt_number:
|
|
3495
|
-
created_at:
|
|
3496
|
-
created_at_epoch:
|
|
3497
|
-
metadata_json:
|
|
3498
|
-
import_key:
|
|
3479
|
+
y("idx_user_prompts_session").on(e.session_id),
|
|
3480
|
+
y("idx_user_prompts_project").on(e.project),
|
|
3481
|
+
y("idx_user_prompts_epoch").on(e.created_at_epoch)
|
|
3482
|
+
]), Va = S("session_summaries", {
|
|
3483
|
+
id: b("id").primaryKey(),
|
|
3484
|
+
session_id: b("session_id").references(() => K.id, { onDelete: "cascade" }),
|
|
3485
|
+
project: C("project"),
|
|
3486
|
+
request: C("request"),
|
|
3487
|
+
investigated: C("investigated"),
|
|
3488
|
+
learned: C("learned"),
|
|
3489
|
+
completed: C("completed"),
|
|
3490
|
+
next_steps: C("next_steps"),
|
|
3491
|
+
notes: C("notes"),
|
|
3492
|
+
files_read: C("files_read"),
|
|
3493
|
+
files_edited: C("files_edited"),
|
|
3494
|
+
prompt_number: b("prompt_number"),
|
|
3495
|
+
created_at: C("created_at").notNull(),
|
|
3496
|
+
created_at_epoch: b("created_at_epoch").notNull(),
|
|
3497
|
+
metadata_json: C("metadata_json"),
|
|
3498
|
+
import_key: C("import_key")
|
|
3499
3499
|
}, (e) => [
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
]), Ha =
|
|
3504
|
-
op_id:
|
|
3505
|
-
entity_type:
|
|
3506
|
-
entity_id:
|
|
3507
|
-
op_type:
|
|
3508
|
-
payload_json:
|
|
3509
|
-
clock_rev:
|
|
3510
|
-
clock_updated_at:
|
|
3511
|
-
clock_device_id:
|
|
3512
|
-
device_id:
|
|
3513
|
-
created_at:
|
|
3514
|
-
scope_id:
|
|
3500
|
+
y("idx_session_summaries_session").on(e.session_id),
|
|
3501
|
+
y("idx_session_summaries_project").on(e.project),
|
|
3502
|
+
y("idx_session_summaries_epoch").on(e.created_at_epoch)
|
|
3503
|
+
]), Ha = S("replication_ops", {
|
|
3504
|
+
op_id: C("op_id").primaryKey(),
|
|
3505
|
+
entity_type: C("entity_type").notNull(),
|
|
3506
|
+
entity_id: C("entity_id").notNull(),
|
|
3507
|
+
op_type: C("op_type").notNull(),
|
|
3508
|
+
payload_json: C("payload_json"),
|
|
3509
|
+
clock_rev: b("clock_rev").notNull(),
|
|
3510
|
+
clock_updated_at: C("clock_updated_at").notNull(),
|
|
3511
|
+
clock_device_id: C("clock_device_id").notNull(),
|
|
3512
|
+
device_id: C("device_id").notNull(),
|
|
3513
|
+
created_at: C("created_at").notNull(),
|
|
3514
|
+
scope_id: C("scope_id")
|
|
3515
3515
|
}, (e) => [
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
]), Ua =
|
|
3520
|
-
peer_device_id:
|
|
3521
|
-
last_applied_cursor:
|
|
3522
|
-
last_acked_cursor:
|
|
3523
|
-
updated_at:
|
|
3524
|
-
}), Wa =
|
|
3525
|
-
peer_device_id:
|
|
3526
|
-
scope_id:
|
|
3527
|
-
last_applied_cursor:
|
|
3528
|
-
last_acked_cursor:
|
|
3529
|
-
updated_at:
|
|
3530
|
-
}, (e) => [
|
|
3531
|
-
peer_device_id:
|
|
3532
|
-
name:
|
|
3533
|
-
pinned_fingerprint:
|
|
3534
|
-
public_key:
|
|
3535
|
-
addresses_json:
|
|
3536
|
-
manual_addresses_json:
|
|
3537
|
-
explicit_pairing_fingerprint:
|
|
3538
|
-
explicit_pairing_saved_at:
|
|
3539
|
-
last_success_address:
|
|
3540
|
-
claimed_local_actor:
|
|
3541
|
-
actor_id:
|
|
3542
|
-
projects_include_json:
|
|
3543
|
-
projects_exclude_json:
|
|
3544
|
-
created_at:
|
|
3545
|
-
last_seen_at:
|
|
3546
|
-
last_sync_at:
|
|
3547
|
-
last_error:
|
|
3548
|
-
runtime_version:
|
|
3549
|
-
runtime_version_observed_at:
|
|
3550
|
-
sync_features_json:
|
|
3551
|
-
sync_features_observed_at:
|
|
3552
|
-
relay_retry_after:
|
|
3553
|
-
relay_rejections:
|
|
3554
|
-
highest_observed_direct_signature_version:
|
|
3555
|
-
discovered_via_coordinator_id:
|
|
3556
|
-
discovered_via_group_id:
|
|
3557
|
-
trust_provenance:
|
|
3558
|
-
pending_bootstrap_grant_id:
|
|
3559
|
-
}), Ka =
|
|
3560
|
-
peer_device_id:
|
|
3561
|
-
projects_include_json:
|
|
3562
|
-
projects_exclude_json:
|
|
3563
|
-
}), qa =
|
|
3564
|
-
peer_device_id:
|
|
3565
|
-
highest_observed_direct_signature_version:
|
|
3566
|
-
}), Ja =
|
|
3567
|
-
nonce:
|
|
3568
|
-
device_id:
|
|
3569
|
-
created_at:
|
|
3570
|
-
}), Ya =
|
|
3571
|
-
device_id:
|
|
3572
|
-
public_key:
|
|
3573
|
-
fingerprint:
|
|
3574
|
-
created_at:
|
|
3575
|
-
}), Xa =
|
|
3576
|
-
id:
|
|
3577
|
-
peer_device_id:
|
|
3578
|
-
started_at:
|
|
3579
|
-
finished_at:
|
|
3580
|
-
ok:
|
|
3581
|
-
ops_in:
|
|
3582
|
-
ops_out:
|
|
3583
|
-
error:
|
|
3584
|
-
local_sync_capability:
|
|
3585
|
-
peer_sync_capability:
|
|
3586
|
-
negotiated_sync_capability:
|
|
3587
|
-
failure_category:
|
|
3588
|
-
transport:
|
|
3516
|
+
y("idx_replication_ops_created").on(e.created_at, e.op_id),
|
|
3517
|
+
y("idx_replication_ops_entity").on(e.entity_type, e.entity_id),
|
|
3518
|
+
y("idx_replication_ops_scope_created").on(e.scope_id, e.created_at, e.op_id)
|
|
3519
|
+
]), Ua = S("replication_cursors", {
|
|
3520
|
+
peer_device_id: C("peer_device_id").primaryKey(),
|
|
3521
|
+
last_applied_cursor: C("last_applied_cursor"),
|
|
3522
|
+
last_acked_cursor: C("last_acked_cursor"),
|
|
3523
|
+
updated_at: C("updated_at").notNull()
|
|
3524
|
+
}), Wa = S("replication_cursors_v2", {
|
|
3525
|
+
peer_device_id: C("peer_device_id").notNull(),
|
|
3526
|
+
scope_id: C("scope_id").notNull(),
|
|
3527
|
+
last_applied_cursor: C("last_applied_cursor"),
|
|
3528
|
+
last_acked_cursor: C("last_acked_cursor"),
|
|
3529
|
+
updated_at: C("updated_at").notNull()
|
|
3530
|
+
}, (e) => [x({ columns: [e.peer_device_id, e.scope_id] }), y("idx_replication_cursors_v2_scope").on(e.scope_id)]), Ga = S("sync_peers", {
|
|
3531
|
+
peer_device_id: C("peer_device_id").primaryKey(),
|
|
3532
|
+
name: C("name"),
|
|
3533
|
+
pinned_fingerprint: C("pinned_fingerprint"),
|
|
3534
|
+
public_key: C("public_key"),
|
|
3535
|
+
addresses_json: C("addresses_json"),
|
|
3536
|
+
manual_addresses_json: C("manual_addresses_json"),
|
|
3537
|
+
explicit_pairing_fingerprint: C("explicit_pairing_fingerprint"),
|
|
3538
|
+
explicit_pairing_saved_at: C("explicit_pairing_saved_at"),
|
|
3539
|
+
last_success_address: C("last_success_address"),
|
|
3540
|
+
claimed_local_actor: b("claimed_local_actor").notNull().default(0),
|
|
3541
|
+
actor_id: C("actor_id"),
|
|
3542
|
+
projects_include_json: C("projects_include_json"),
|
|
3543
|
+
projects_exclude_json: C("projects_exclude_json"),
|
|
3544
|
+
created_at: C("created_at").notNull(),
|
|
3545
|
+
last_seen_at: C("last_seen_at"),
|
|
3546
|
+
last_sync_at: C("last_sync_at"),
|
|
3547
|
+
last_error: C("last_error"),
|
|
3548
|
+
runtime_version: C("runtime_version"),
|
|
3549
|
+
runtime_version_observed_at: C("runtime_version_observed_at"),
|
|
3550
|
+
sync_features_json: C("sync_features_json"),
|
|
3551
|
+
sync_features_observed_at: C("sync_features_observed_at"),
|
|
3552
|
+
relay_retry_after: C("relay_retry_after"),
|
|
3553
|
+
relay_rejections: b("relay_rejections").notNull().default(0),
|
|
3554
|
+
highest_observed_direct_signature_version: b("highest_observed_direct_signature_version"),
|
|
3555
|
+
discovered_via_coordinator_id: C("discovered_via_coordinator_id"),
|
|
3556
|
+
discovered_via_group_id: C("discovered_via_group_id"),
|
|
3557
|
+
trust_provenance: C("trust_provenance"),
|
|
3558
|
+
pending_bootstrap_grant_id: C("pending_bootstrap_grant_id")
|
|
3559
|
+
}), Ka = S("peer_project_filter_retention", {
|
|
3560
|
+
peer_device_id: C("peer_device_id").primaryKey(),
|
|
3561
|
+
projects_include_json: C("projects_include_json"),
|
|
3562
|
+
projects_exclude_json: C("projects_exclude_json")
|
|
3563
|
+
}), qa = S("sync_peer_signature_state", {
|
|
3564
|
+
peer_device_id: C("peer_device_id").primaryKey(),
|
|
3565
|
+
highest_observed_direct_signature_version: b("highest_observed_direct_signature_version").notNull()
|
|
3566
|
+
}), Ja = S("sync_nonces", {
|
|
3567
|
+
nonce: C("nonce").primaryKey(),
|
|
3568
|
+
device_id: C("device_id").notNull(),
|
|
3569
|
+
created_at: C("created_at").notNull()
|
|
3570
|
+
}), Ya = S("sync_device", {
|
|
3571
|
+
device_id: C("device_id").primaryKey(),
|
|
3572
|
+
public_key: C("public_key").notNull(),
|
|
3573
|
+
fingerprint: C("fingerprint").notNull(),
|
|
3574
|
+
created_at: C("created_at").notNull()
|
|
3575
|
+
}), Xa = S("sync_attempts", {
|
|
3576
|
+
id: b("id").primaryKey({ autoIncrement: !0 }),
|
|
3577
|
+
peer_device_id: C("peer_device_id").notNull(),
|
|
3578
|
+
started_at: C("started_at").notNull(),
|
|
3579
|
+
finished_at: C("finished_at"),
|
|
3580
|
+
ok: b("ok").notNull(),
|
|
3581
|
+
ops_in: b("ops_in").notNull(),
|
|
3582
|
+
ops_out: b("ops_out").notNull(),
|
|
3583
|
+
error: C("error"),
|
|
3584
|
+
local_sync_capability: C("local_sync_capability"),
|
|
3585
|
+
peer_sync_capability: C("peer_sync_capability"),
|
|
3586
|
+
negotiated_sync_capability: C("negotiated_sync_capability"),
|
|
3587
|
+
failure_category: C("failure_category"),
|
|
3588
|
+
transport: C("transport")
|
|
3589
3589
|
}, (e) => [
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
]), Za =
|
|
3595
|
-
id:
|
|
3596
|
-
peer_device_id:
|
|
3597
|
-
op_id:
|
|
3598
|
-
entity_type:
|
|
3599
|
-
entity_id:
|
|
3600
|
-
scope_id:
|
|
3601
|
-
reason:
|
|
3602
|
-
created_at:
|
|
3603
|
-
}, (e) => [
|
|
3604
|
-
id:
|
|
3605
|
-
last_error:
|
|
3606
|
-
last_traceback:
|
|
3607
|
-
last_error_at:
|
|
3608
|
-
last_ok_at:
|
|
3609
|
-
phase:
|
|
3610
|
-
}), $a =
|
|
3611
|
-
id:
|
|
3612
|
-
generation:
|
|
3613
|
-
snapshot_id:
|
|
3614
|
-
baseline_cursor:
|
|
3615
|
-
retained_floor_cursor:
|
|
3616
|
-
updated_at:
|
|
3617
|
-
}), eo =
|
|
3618
|
-
scope_id:
|
|
3619
|
-
generation:
|
|
3620
|
-
snapshot_id:
|
|
3621
|
-
baseline_cursor:
|
|
3622
|
-
retained_floor_cursor:
|
|
3623
|
-
updated_at:
|
|
3624
|
-
}), to =
|
|
3625
|
-
id:
|
|
3626
|
-
last_run_at:
|
|
3627
|
-
last_duration_ms:
|
|
3628
|
-
last_deleted_ops:
|
|
3629
|
-
last_estimated_bytes_before:
|
|
3630
|
-
last_estimated_bytes_after:
|
|
3631
|
-
retained_floor_cursor:
|
|
3632
|
-
last_error:
|
|
3633
|
-
last_error_at:
|
|
3634
|
-
}), no =
|
|
3635
|
-
scope_id:
|
|
3636
|
-
last_run_at:
|
|
3637
|
-
last_duration_ms:
|
|
3638
|
-
last_deleted_ops:
|
|
3639
|
-
last_estimated_bytes_before:
|
|
3640
|
-
last_estimated_bytes_after:
|
|
3641
|
-
retained_floor_cursor:
|
|
3642
|
-
last_error:
|
|
3643
|
-
last_error_at:
|
|
3644
|
-
}), ro =
|
|
3645
|
-
id:
|
|
3646
|
-
created_at:
|
|
3647
|
-
inserted_events:
|
|
3648
|
-
skipped_invalid:
|
|
3649
|
-
skipped_duplicate:
|
|
3650
|
-
skipped_conflict:
|
|
3651
|
-
}), io =
|
|
3652
|
-
id:
|
|
3653
|
-
inserted_events:
|
|
3654
|
-
skipped_events:
|
|
3655
|
-
skipped_invalid:
|
|
3656
|
-
skipped_duplicate:
|
|
3657
|
-
skipped_conflict:
|
|
3658
|
-
updated_at:
|
|
3659
|
-
}), ao =
|
|
3660
|
-
coordinator_id:
|
|
3661
|
-
group_id:
|
|
3662
|
-
projects_include_json:
|
|
3663
|
-
projects_exclude_json:
|
|
3664
|
-
auto_seed_scope:
|
|
3665
|
-
default_space_scope_id:
|
|
3666
|
-
auto_grant_default_space_on_join:
|
|
3667
|
-
updated_at:
|
|
3668
|
-
}, (e) => ({ pk:
|
|
3669
|
-
actor_id:
|
|
3670
|
-
display_name:
|
|
3671
|
-
is_local:
|
|
3672
|
-
status:
|
|
3673
|
-
merged_into_actor_id:
|
|
3674
|
-
created_at:
|
|
3675
|
-
updated_at:
|
|
3590
|
+
y("idx_sync_attempts_peer_started").on(e.peer_device_id, e.started_at),
|
|
3591
|
+
y("idx_sync_attempts_occurred").on(v`CASE WHEN ${e.finished_at} IS NULL THEN ${e.started_at} ELSE ${e.finished_at} END`, e.id),
|
|
3592
|
+
y("idx_sync_attempts_error_occurred").on(v`CASE WHEN ${e.finished_at} IS NULL THEN ${e.started_at} ELSE ${e.finished_at} END`, e.id).where(v`${e.ok} = 0`),
|
|
3593
|
+
y("idx_sync_attempts_success_occurred").on(v`CASE WHEN ${e.finished_at} IS NULL THEN ${e.started_at} ELSE ${e.finished_at} END`, e.id).where(v`${e.ok} <> 0`)
|
|
3594
|
+
]), Za = S("sync_scope_rejections", {
|
|
3595
|
+
id: b("id").primaryKey({ autoIncrement: !0 }),
|
|
3596
|
+
peer_device_id: C("peer_device_id"),
|
|
3597
|
+
op_id: C("op_id").notNull(),
|
|
3598
|
+
entity_type: C("entity_type").notNull(),
|
|
3599
|
+
entity_id: C("entity_id").notNull(),
|
|
3600
|
+
scope_id: C("scope_id"),
|
|
3601
|
+
reason: C("reason").notNull(),
|
|
3602
|
+
created_at: C("created_at").notNull()
|
|
3603
|
+
}, (e) => [y("idx_sync_scope_rejections_peer_created").on(e.peer_device_id, e.created_at), y("idx_sync_scope_rejections_scope_created").on(e.scope_id, e.created_at)]), Qa = S("sync_daemon_state", {
|
|
3604
|
+
id: b("id").primaryKey(),
|
|
3605
|
+
last_error: C("last_error"),
|
|
3606
|
+
last_traceback: C("last_traceback"),
|
|
3607
|
+
last_error_at: C("last_error_at"),
|
|
3608
|
+
last_ok_at: C("last_ok_at"),
|
|
3609
|
+
phase: C("phase")
|
|
3610
|
+
}), $a = S("sync_reset_state", {
|
|
3611
|
+
id: b("id").primaryKey(),
|
|
3612
|
+
generation: b("generation").notNull(),
|
|
3613
|
+
snapshot_id: C("snapshot_id").notNull(),
|
|
3614
|
+
baseline_cursor: C("baseline_cursor"),
|
|
3615
|
+
retained_floor_cursor: C("retained_floor_cursor"),
|
|
3616
|
+
updated_at: C("updated_at").notNull()
|
|
3617
|
+
}), eo = S("sync_reset_state_v2", {
|
|
3618
|
+
scope_id: C("scope_id").primaryKey(),
|
|
3619
|
+
generation: b("generation").notNull(),
|
|
3620
|
+
snapshot_id: C("snapshot_id").notNull(),
|
|
3621
|
+
baseline_cursor: C("baseline_cursor"),
|
|
3622
|
+
retained_floor_cursor: C("retained_floor_cursor"),
|
|
3623
|
+
updated_at: C("updated_at").notNull()
|
|
3624
|
+
}), to = S("sync_retention_state", {
|
|
3625
|
+
id: b("id").primaryKey(),
|
|
3626
|
+
last_run_at: C("last_run_at"),
|
|
3627
|
+
last_duration_ms: b("last_duration_ms"),
|
|
3628
|
+
last_deleted_ops: b("last_deleted_ops").notNull().default(0),
|
|
3629
|
+
last_estimated_bytes_before: b("last_estimated_bytes_before"),
|
|
3630
|
+
last_estimated_bytes_after: b("last_estimated_bytes_after"),
|
|
3631
|
+
retained_floor_cursor: C("retained_floor_cursor"),
|
|
3632
|
+
last_error: C("last_error"),
|
|
3633
|
+
last_error_at: C("last_error_at")
|
|
3634
|
+
}), no = S("sync_retention_state_v2", {
|
|
3635
|
+
scope_id: C("scope_id").primaryKey(),
|
|
3636
|
+
last_run_at: C("last_run_at"),
|
|
3637
|
+
last_duration_ms: b("last_duration_ms"),
|
|
3638
|
+
last_deleted_ops: b("last_deleted_ops").notNull().default(0),
|
|
3639
|
+
last_estimated_bytes_before: b("last_estimated_bytes_before"),
|
|
3640
|
+
last_estimated_bytes_after: b("last_estimated_bytes_after"),
|
|
3641
|
+
retained_floor_cursor: C("retained_floor_cursor"),
|
|
3642
|
+
last_error: C("last_error"),
|
|
3643
|
+
last_error_at: C("last_error_at")
|
|
3644
|
+
}), ro = S("raw_event_ingest_samples", {
|
|
3645
|
+
id: b("id").primaryKey({ autoIncrement: !0 }),
|
|
3646
|
+
created_at: C("created_at").notNull(),
|
|
3647
|
+
inserted_events: b("inserted_events").notNull().default(0),
|
|
3648
|
+
skipped_invalid: b("skipped_invalid").notNull().default(0),
|
|
3649
|
+
skipped_duplicate: b("skipped_duplicate").notNull().default(0),
|
|
3650
|
+
skipped_conflict: b("skipped_conflict").notNull().default(0)
|
|
3651
|
+
}), io = S("raw_event_ingest_stats", {
|
|
3652
|
+
id: b("id").primaryKey(),
|
|
3653
|
+
inserted_events: b("inserted_events").notNull().default(0),
|
|
3654
|
+
skipped_events: b("skipped_events").notNull().default(0),
|
|
3655
|
+
skipped_invalid: b("skipped_invalid").notNull().default(0),
|
|
3656
|
+
skipped_duplicate: b("skipped_duplicate").notNull().default(0),
|
|
3657
|
+
skipped_conflict: b("skipped_conflict").notNull().default(0),
|
|
3658
|
+
updated_at: C("updated_at").notNull()
|
|
3659
|
+
}), ao = S("coordinator_group_preferences", {
|
|
3660
|
+
coordinator_id: C("coordinator_id").notNull(),
|
|
3661
|
+
group_id: C("group_id").notNull(),
|
|
3662
|
+
projects_include_json: C("projects_include_json"),
|
|
3663
|
+
projects_exclude_json: C("projects_exclude_json"),
|
|
3664
|
+
auto_seed_scope: b("auto_seed_scope").notNull().default(1),
|
|
3665
|
+
default_space_scope_id: C("default_space_scope_id"),
|
|
3666
|
+
auto_grant_default_space_on_join: b("auto_grant_default_space_on_join").notNull().default(0),
|
|
3667
|
+
updated_at: C("updated_at").notNull()
|
|
3668
|
+
}, (e) => ({ pk: x({ columns: [e.coordinator_id, e.group_id] }) })), oo = S("actors", {
|
|
3669
|
+
actor_id: C("actor_id").primaryKey(),
|
|
3670
|
+
display_name: C("display_name").notNull(),
|
|
3671
|
+
is_local: b("is_local").notNull().default(0),
|
|
3672
|
+
status: C("status").notNull().default("active"),
|
|
3673
|
+
merged_into_actor_id: C("merged_into_actor_id"),
|
|
3674
|
+
created_at: C("created_at").notNull(),
|
|
3675
|
+
updated_at: C("updated_at").notNull()
|
|
3676
3676
|
}, (e) => ({
|
|
3677
|
-
isLocalIdx:
|
|
3678
|
-
statusIdx:
|
|
3679
|
-
})), so =
|
|
3680
|
-
review_item_id:
|
|
3681
|
-
source_fingerprint:
|
|
3682
|
-
decision:
|
|
3683
|
-
decision_input_json:
|
|
3684
|
-
preview_json:
|
|
3685
|
-
decided_by_identity_id:
|
|
3686
|
-
decided_by_device_id:
|
|
3687
|
-
resolved_at:
|
|
3688
|
-
}, (e) => [
|
|
3689
|
-
coordinator_id:
|
|
3690
|
-
group_id:
|
|
3691
|
-
kind:
|
|
3692
|
-
reference_id:
|
|
3693
|
-
code:
|
|
3694
|
-
status:
|
|
3695
|
-
first_seen_at:
|
|
3696
|
-
last_seen_at:
|
|
3697
|
-
resolved_at:
|
|
3698
|
-
occurrence_count:
|
|
3699
|
-
updated_at:
|
|
3677
|
+
isLocalIdx: y("idx_actors_is_local").on(e.is_local),
|
|
3678
|
+
statusIdx: y("idx_actors_status").on(e.status)
|
|
3679
|
+
})), so = S("recipient_policy_review_resolutions", {
|
|
3680
|
+
review_item_id: C("review_item_id").notNull(),
|
|
3681
|
+
source_fingerprint: C("source_fingerprint").notNull(),
|
|
3682
|
+
decision: C("decision").notNull(),
|
|
3683
|
+
decision_input_json: C("decision_input_json").notNull(),
|
|
3684
|
+
preview_json: C("preview_json").notNull(),
|
|
3685
|
+
decided_by_identity_id: C("decided_by_identity_id").notNull(),
|
|
3686
|
+
decided_by_device_id: C("decided_by_device_id").notNull(),
|
|
3687
|
+
resolved_at: C("resolved_at").notNull()
|
|
3688
|
+
}, (e) => [x({ columns: [e.review_item_id, e.source_fingerprint] })]), co = S("coordinator_enrollment_reconciliation_issues", {
|
|
3689
|
+
coordinator_id: C("coordinator_id").notNull(),
|
|
3690
|
+
group_id: C("group_id").notNull(),
|
|
3691
|
+
kind: C("kind").notNull(),
|
|
3692
|
+
reference_id: C("reference_id").notNull(),
|
|
3693
|
+
code: C("code").notNull(),
|
|
3694
|
+
status: C("status").notNull().default("open"),
|
|
3695
|
+
first_seen_at: C("first_seen_at").notNull(),
|
|
3696
|
+
last_seen_at: C("last_seen_at").notNull(),
|
|
3697
|
+
resolved_at: C("resolved_at"),
|
|
3698
|
+
occurrence_count: b("occurrence_count").notNull().default(1),
|
|
3699
|
+
updated_at: C("updated_at").notNull()
|
|
3700
3700
|
}, (e) => [
|
|
3701
|
-
|
|
3701
|
+
x({ columns: [
|
|
3702
3702
|
e.coordinator_id,
|
|
3703
3703
|
e.group_id,
|
|
3704
3704
|
e.kind,
|
|
3705
3705
|
e.reference_id,
|
|
3706
3706
|
e.code
|
|
3707
3707
|
] }),
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
]), lo =
|
|
3711
|
-
team_id:
|
|
3712
|
-
display_name:
|
|
3713
|
-
status:
|
|
3714
|
-
device_eligibility_mode:
|
|
3715
|
-
provenance:
|
|
3716
|
-
revision:
|
|
3717
|
-
migration_state:
|
|
3718
|
-
source_fingerprint:
|
|
3719
|
-
idempotency_key:
|
|
3720
|
-
created_at:
|
|
3721
|
-
updated_at:
|
|
3722
|
-
}), uo =
|
|
3723
|
-
team_id:
|
|
3724
|
-
identity_id:
|
|
3725
|
-
role:
|
|
3726
|
-
status:
|
|
3727
|
-
provenance:
|
|
3728
|
-
revision:
|
|
3729
|
-
migration_state:
|
|
3730
|
-
source_fingerprint:
|
|
3731
|
-
idempotency_key:
|
|
3732
|
-
created_at:
|
|
3733
|
-
updated_at:
|
|
3708
|
+
y("idx_coordinator_enrollment_issues_boundary_status").on(e.coordinator_id, e.group_id, e.status),
|
|
3709
|
+
y("idx_coordinator_enrollment_issues_status_recent").on(e.status, e.last_seen_at, e.resolved_at)
|
|
3710
|
+
]), lo = S("policy_teams", {
|
|
3711
|
+
team_id: C("team_id").primaryKey(),
|
|
3712
|
+
display_name: C("display_name").notNull(),
|
|
3713
|
+
status: C("status").notNull(),
|
|
3714
|
+
device_eligibility_mode: C("device_eligibility_mode").notNull().default("person_all_devices"),
|
|
3715
|
+
provenance: C("provenance").notNull(),
|
|
3716
|
+
revision: C("revision").notNull(),
|
|
3717
|
+
migration_state: C("migration_state").notNull(),
|
|
3718
|
+
source_fingerprint: C("source_fingerprint"),
|
|
3719
|
+
idempotency_key: C("idempotency_key").notNull().unique(),
|
|
3720
|
+
created_at: C("created_at").notNull(),
|
|
3721
|
+
updated_at: C("updated_at").notNull()
|
|
3722
|
+
}), uo = S("policy_team_memberships", {
|
|
3723
|
+
team_id: C("team_id").notNull(),
|
|
3724
|
+
identity_id: C("identity_id").notNull(),
|
|
3725
|
+
role: C("role").notNull(),
|
|
3726
|
+
status: C("status").notNull(),
|
|
3727
|
+
provenance: C("provenance").notNull(),
|
|
3728
|
+
revision: C("revision").notNull(),
|
|
3729
|
+
migration_state: C("migration_state").notNull(),
|
|
3730
|
+
source_fingerprint: C("source_fingerprint"),
|
|
3731
|
+
idempotency_key: C("idempotency_key").notNull().unique(),
|
|
3732
|
+
created_at: C("created_at").notNull(),
|
|
3733
|
+
updated_at: C("updated_at").notNull()
|
|
3734
3734
|
}, (e) => ({
|
|
3735
|
-
pk:
|
|
3736
|
-
identityStatusIdx:
|
|
3737
|
-
})), fo =
|
|
3738
|
-
team_id:
|
|
3739
|
-
device_id:
|
|
3740
|
-
decision:
|
|
3741
|
-
assignment_version:
|
|
3742
|
-
provenance:
|
|
3743
|
-
revision:
|
|
3744
|
-
created_at:
|
|
3745
|
-
updated_at:
|
|
3746
|
-
}, (e) => [
|
|
3747
|
-
device_id:
|
|
3748
|
-
identity_id:
|
|
3749
|
-
display_name:
|
|
3750
|
-
status:
|
|
3751
|
-
provenance:
|
|
3752
|
-
revision:
|
|
3753
|
-
migration_state:
|
|
3754
|
-
assignment_version:
|
|
3755
|
-
source_fingerprint:
|
|
3756
|
-
idempotency_key:
|
|
3757
|
-
created_at:
|
|
3758
|
-
updated_at:
|
|
3759
|
-
}, (e) => ({ identityStatusIdx:
|
|
3760
|
-
commit_digest:
|
|
3761
|
-
reviewed_inventory_digest:
|
|
3762
|
-
request_json:
|
|
3763
|
-
outcomes_json:
|
|
3764
|
-
write_count:
|
|
3765
|
-
decided_by_identity_id:
|
|
3766
|
-
decided_by_device_id:
|
|
3767
|
-
created_at:
|
|
3768
|
-
}), ho =
|
|
3769
|
-
event_id:
|
|
3770
|
-
commit_digest:
|
|
3771
|
-
device_id:
|
|
3772
|
-
previous_identity_id:
|
|
3773
|
-
target_identity_id:
|
|
3774
|
-
action:
|
|
3775
|
-
previous_assignment_version:
|
|
3776
|
-
resulting_assignment_version:
|
|
3777
|
-
decided_by_identity_id:
|
|
3778
|
-
decided_by_device_id:
|
|
3779
|
-
created_at:
|
|
3780
|
-
}, (e) => [
|
|
3781
|
-
canonical_project_identity:
|
|
3782
|
-
recipient_kind:
|
|
3783
|
-
recipient_id:
|
|
3784
|
-
status:
|
|
3785
|
-
provenance:
|
|
3786
|
-
policy_revision:
|
|
3787
|
-
migration_state:
|
|
3788
|
-
source_fingerprint:
|
|
3789
|
-
idempotency_key:
|
|
3790
|
-
created_at:
|
|
3791
|
-
updated_at:
|
|
3735
|
+
pk: x({ columns: [e.team_id, e.identity_id] }),
|
|
3736
|
+
identityStatusIdx: y("idx_policy_team_memberships_identity_status").on(e.identity_id, e.status)
|
|
3737
|
+
})), fo = S("policy_team_device_decisions", {
|
|
3738
|
+
team_id: C("team_id").notNull().references(() => lo.team_id, { onDelete: "cascade" }),
|
|
3739
|
+
device_id: C("device_id").notNull(),
|
|
3740
|
+
decision: C("decision").notNull(),
|
|
3741
|
+
assignment_version: b("assignment_version").notNull().default(0),
|
|
3742
|
+
provenance: C("provenance").notNull(),
|
|
3743
|
+
revision: C("revision").notNull(),
|
|
3744
|
+
created_at: C("created_at").notNull(),
|
|
3745
|
+
updated_at: C("updated_at").notNull()
|
|
3746
|
+
}, (e) => [x({ columns: [e.team_id, e.device_id] }), y("idx_policy_team_device_decisions_device").on(e.device_id)]), po = S("identity_devices", {
|
|
3747
|
+
device_id: C("device_id").primaryKey(),
|
|
3748
|
+
identity_id: C("identity_id").notNull(),
|
|
3749
|
+
display_name: C("display_name").notNull(),
|
|
3750
|
+
status: C("status").notNull(),
|
|
3751
|
+
provenance: C("provenance").notNull(),
|
|
3752
|
+
revision: C("revision").notNull(),
|
|
3753
|
+
migration_state: C("migration_state").notNull(),
|
|
3754
|
+
assignment_version: b("assignment_version").notNull().default(0),
|
|
3755
|
+
source_fingerprint: C("source_fingerprint"),
|
|
3756
|
+
idempotency_key: C("idempotency_key").notNull().unique(),
|
|
3757
|
+
created_at: C("created_at").notNull(),
|
|
3758
|
+
updated_at: C("updated_at").notNull()
|
|
3759
|
+
}, (e) => ({ identityStatusIdx: y("idx_identity_devices_identity_status").on(e.identity_id, e.status) })), mo = S("device_identity_binding_commits", {
|
|
3760
|
+
commit_digest: C("commit_digest").primaryKey(),
|
|
3761
|
+
reviewed_inventory_digest: C("reviewed_inventory_digest").notNull(),
|
|
3762
|
+
request_json: C("request_json").notNull(),
|
|
3763
|
+
outcomes_json: C("outcomes_json").notNull(),
|
|
3764
|
+
write_count: b("write_count").notNull(),
|
|
3765
|
+
decided_by_identity_id: C("decided_by_identity_id").notNull(),
|
|
3766
|
+
decided_by_device_id: C("decided_by_device_id").notNull(),
|
|
3767
|
+
created_at: C("created_at").notNull()
|
|
3768
|
+
}), ho = S("device_identity_binding_audit", {
|
|
3769
|
+
event_id: C("event_id").primaryKey(),
|
|
3770
|
+
commit_digest: C("commit_digest").notNull().references(() => mo.commit_digest),
|
|
3771
|
+
device_id: C("device_id").notNull(),
|
|
3772
|
+
previous_identity_id: C("previous_identity_id"),
|
|
3773
|
+
target_identity_id: C("target_identity_id").notNull(),
|
|
3774
|
+
action: C("action").notNull(),
|
|
3775
|
+
previous_assignment_version: b("previous_assignment_version"),
|
|
3776
|
+
resulting_assignment_version: b("resulting_assignment_version").notNull(),
|
|
3777
|
+
decided_by_identity_id: C("decided_by_identity_id").notNull(),
|
|
3778
|
+
decided_by_device_id: C("decided_by_device_id").notNull(),
|
|
3779
|
+
created_at: C("created_at").notNull()
|
|
3780
|
+
}, (e) => [w("idx_device_identity_binding_audit_commit_device").on(e.commit_digest, e.device_id), y("idx_device_identity_binding_audit_device_created").on(e.device_id, e.created_at, e.event_id)]), go = S("project_recipients", {
|
|
3781
|
+
canonical_project_identity: C("canonical_project_identity").notNull(),
|
|
3782
|
+
recipient_kind: C("recipient_kind").notNull(),
|
|
3783
|
+
recipient_id: C("recipient_id").notNull(),
|
|
3784
|
+
status: C("status").notNull(),
|
|
3785
|
+
provenance: C("provenance").notNull(),
|
|
3786
|
+
policy_revision: C("policy_revision").notNull(),
|
|
3787
|
+
migration_state: C("migration_state").notNull(),
|
|
3788
|
+
source_fingerprint: C("source_fingerprint"),
|
|
3789
|
+
idempotency_key: C("idempotency_key").notNull().unique(),
|
|
3790
|
+
created_at: C("created_at").notNull(),
|
|
3791
|
+
updated_at: C("updated_at").notNull()
|
|
3792
3792
|
}, (e) => ({
|
|
3793
|
-
pk:
|
|
3793
|
+
pk: x({ columns: [
|
|
3794
3794
|
e.canonical_project_identity,
|
|
3795
3795
|
e.recipient_kind,
|
|
3796
3796
|
e.recipient_id
|
|
3797
3797
|
] }),
|
|
3798
|
-
projectStatusIdx:
|
|
3799
|
-
recipientStatusIdx:
|
|
3800
|
-
})), _o =
|
|
3801
|
-
attempt_id:
|
|
3802
|
-
candidate_id:
|
|
3803
|
-
coordinator_id:
|
|
3804
|
-
group_id:
|
|
3805
|
-
state:
|
|
3806
|
-
display_name:
|
|
3807
|
-
roster_fingerprint:
|
|
3808
|
-
projection_fingerprint:
|
|
3809
|
-
finish_digest:
|
|
3810
|
-
safe_error_code:
|
|
3811
|
-
completed_team_id:
|
|
3812
|
-
created_at:
|
|
3813
|
-
updated_at:
|
|
3814
|
-
completed_at:
|
|
3815
|
-
superseded_at:
|
|
3798
|
+
projectStatusIdx: y("idx_project_recipients_project_status").on(e.canonical_project_identity, e.status),
|
|
3799
|
+
recipientStatusIdx: y("idx_project_recipients_recipient_status").on(e.recipient_kind, e.recipient_id, e.status)
|
|
3800
|
+
})), _o = S("legacy_team_setup_drafts", {
|
|
3801
|
+
attempt_id: C("attempt_id").primaryKey(),
|
|
3802
|
+
candidate_id: C("candidate_id").notNull(),
|
|
3803
|
+
coordinator_id: C("coordinator_id").notNull(),
|
|
3804
|
+
group_id: C("group_id").notNull(),
|
|
3805
|
+
state: C("state").notNull().default("needs_setup"),
|
|
3806
|
+
display_name: C("display_name").notNull(),
|
|
3807
|
+
roster_fingerprint: C("roster_fingerprint").notNull(),
|
|
3808
|
+
projection_fingerprint: C("projection_fingerprint").notNull(),
|
|
3809
|
+
finish_digest: C("finish_digest"),
|
|
3810
|
+
safe_error_code: C("safe_error_code"),
|
|
3811
|
+
completed_team_id: C("completed_team_id"),
|
|
3812
|
+
created_at: C("created_at").notNull(),
|
|
3813
|
+
updated_at: C("updated_at").notNull(),
|
|
3814
|
+
completed_at: C("completed_at"),
|
|
3815
|
+
superseded_at: C("superseded_at")
|
|
3816
3816
|
}, (e) => [
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
]), vo =
|
|
3821
|
-
attempt_id:
|
|
3822
|
-
finish_digest:
|
|
3823
|
-
candidate_ref:
|
|
3824
|
-
confirmed_access_delta_digest:
|
|
3825
|
-
completed_team_id:
|
|
3826
|
-
response_json:
|
|
3827
|
-
completed_at:
|
|
3828
|
-
created_at:
|
|
3829
|
-
}, (e) => [
|
|
3830
|
-
attempt_id:
|
|
3831
|
-
device_id:
|
|
3832
|
-
device_ref:
|
|
3833
|
-
key_fingerprint:
|
|
3834
|
-
display_name:
|
|
3835
|
-
enabled:
|
|
3836
|
-
existing_identity_id:
|
|
3837
|
-
existing_assignment_version:
|
|
3838
|
-
verified_evidence_kind:
|
|
3839
|
-
identity_evidence:
|
|
3840
|
-
decision:
|
|
3841
|
-
target_identity_id:
|
|
3842
|
-
expected_assignment_kind:
|
|
3843
|
-
expected_assignment_version:
|
|
3844
|
-
updated_at:
|
|
3817
|
+
y("idx_legacy_team_setup_drafts_candidate_state").on(e.candidate_id, e.state, e.created_at),
|
|
3818
|
+
y("idx_legacy_team_setup_drafts_state_updated").on(e.state, e.updated_at),
|
|
3819
|
+
y("idx_legacy_team_setup_drafts_finish_digest").on(e.finish_digest)
|
|
3820
|
+
]), vo = S("legacy_team_setup_completions", {
|
|
3821
|
+
attempt_id: C("attempt_id").notNull(),
|
|
3822
|
+
finish_digest: C("finish_digest").notNull(),
|
|
3823
|
+
candidate_ref: C("candidate_ref").notNull(),
|
|
3824
|
+
confirmed_access_delta_digest: C("confirmed_access_delta_digest").notNull(),
|
|
3825
|
+
completed_team_id: C("completed_team_id").notNull(),
|
|
3826
|
+
response_json: C("response_json").notNull(),
|
|
3827
|
+
completed_at: C("completed_at").notNull(),
|
|
3828
|
+
created_at: C("created_at").notNull()
|
|
3829
|
+
}, (e) => [w("idx_legacy_team_setup_completions_attempt_finish").on(e.attempt_id, e.finish_digest), y("idx_legacy_team_setup_completions_exact_replay").on(e.candidate_ref, e.attempt_id, e.finish_digest, e.confirmed_access_delta_digest)]), yo = S("legacy_team_setup_draft_devices", {
|
|
3830
|
+
attempt_id: C("attempt_id").notNull().references(() => _o.attempt_id, { onDelete: "cascade" }),
|
|
3831
|
+
device_id: C("device_id").notNull(),
|
|
3832
|
+
device_ref: C("device_ref").notNull(),
|
|
3833
|
+
key_fingerprint: C("key_fingerprint").notNull(),
|
|
3834
|
+
display_name: C("display_name").notNull(),
|
|
3835
|
+
enabled: b("enabled", { mode: "boolean" }).notNull(),
|
|
3836
|
+
existing_identity_id: C("existing_identity_id"),
|
|
3837
|
+
existing_assignment_version: b("existing_assignment_version"),
|
|
3838
|
+
verified_evidence_kind: C("verified_evidence_kind"),
|
|
3839
|
+
identity_evidence: C("identity_evidence"),
|
|
3840
|
+
decision: C("decision").notNull().default("unresolved"),
|
|
3841
|
+
target_identity_id: C("target_identity_id"),
|
|
3842
|
+
expected_assignment_kind: C("expected_assignment_kind"),
|
|
3843
|
+
expected_assignment_version: b("expected_assignment_version"),
|
|
3844
|
+
updated_at: C("updated_at").notNull()
|
|
3845
3845
|
}, (e) => [
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
]), bo =
|
|
3850
|
-
attempt_id:
|
|
3851
|
-
project_ref:
|
|
3852
|
-
source_project_identity:
|
|
3853
|
-
display_name:
|
|
3854
|
-
source_fingerprint:
|
|
3855
|
-
resolution_kind:
|
|
3856
|
-
resolved_project_identity:
|
|
3857
|
-
target_scope_id:
|
|
3858
|
-
updated_at:
|
|
3859
|
-
}, (e) => [
|
|
3860
|
-
canonical_project_identity:
|
|
3861
|
-
display_name:
|
|
3862
|
-
managed_scope_id:
|
|
3863
|
-
coordinator_id:
|
|
3864
|
-
group_id:
|
|
3865
|
-
recipient_identity_id:
|
|
3866
|
-
accepting_device_id:
|
|
3867
|
-
source_operation_id:
|
|
3868
|
-
reviewed_project_set_digest:
|
|
3869
|
-
status:
|
|
3870
|
-
accepted_at:
|
|
3871
|
-
revoked_at:
|
|
3872
|
-
created_at:
|
|
3873
|
-
updated_at:
|
|
3846
|
+
x({ columns: [e.attempt_id, e.device_id] }),
|
|
3847
|
+
w("idx_legacy_team_setup_devices_attempt_ref").on(e.attempt_id, e.device_ref),
|
|
3848
|
+
y("idx_legacy_team_setup_devices_attempt_decision").on(e.attempt_id, e.decision)
|
|
3849
|
+
]), bo = S("legacy_team_setup_draft_projects", {
|
|
3850
|
+
attempt_id: C("attempt_id").notNull().references(() => _o.attempt_id, { onDelete: "cascade" }),
|
|
3851
|
+
project_ref: C("project_ref").notNull(),
|
|
3852
|
+
source_project_identity: C("source_project_identity").notNull(),
|
|
3853
|
+
display_name: C("display_name").notNull(),
|
|
3854
|
+
source_fingerprint: C("source_fingerprint").notNull(),
|
|
3855
|
+
resolution_kind: C("resolution_kind").notNull().default("unresolved"),
|
|
3856
|
+
resolved_project_identity: C("resolved_project_identity"),
|
|
3857
|
+
target_scope_id: C("target_scope_id"),
|
|
3858
|
+
updated_at: C("updated_at").notNull()
|
|
3859
|
+
}, (e) => [x({ columns: [e.attempt_id, e.project_ref] }), y("idx_legacy_team_setup_projects_attempt_resolution").on(e.attempt_id, e.resolution_kind)]), xo = S("recipient_managed_project_projections", {
|
|
3860
|
+
canonical_project_identity: C("canonical_project_identity").notNull(),
|
|
3861
|
+
display_name: C("display_name").notNull(),
|
|
3862
|
+
managed_scope_id: C("managed_scope_id").notNull(),
|
|
3863
|
+
coordinator_id: C("coordinator_id").notNull(),
|
|
3864
|
+
group_id: C("group_id").notNull(),
|
|
3865
|
+
recipient_identity_id: C("recipient_identity_id").notNull(),
|
|
3866
|
+
accepting_device_id: C("accepting_device_id").notNull(),
|
|
3867
|
+
source_operation_id: C("source_operation_id").notNull(),
|
|
3868
|
+
reviewed_project_set_digest: C("reviewed_project_set_digest").notNull(),
|
|
3869
|
+
status: C("status").notNull().default("active"),
|
|
3870
|
+
accepted_at: C("accepted_at").notNull(),
|
|
3871
|
+
revoked_at: C("revoked_at"),
|
|
3872
|
+
created_at: C("created_at").notNull(),
|
|
3873
|
+
updated_at: C("updated_at").notNull()
|
|
3874
3874
|
}, (e) => [
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
]), So =
|
|
3879
|
-
canonical_project_identity:
|
|
3880
|
-
authority_state:
|
|
3881
|
-
generation:
|
|
3882
|
-
desired_devices_digest:
|
|
3883
|
-
current_devices_digest:
|
|
3884
|
-
stable_parity_evidence_digest:
|
|
3885
|
-
stable_parity_passed_at:
|
|
3886
|
-
fresh_snapshot_fingerprint:
|
|
3887
|
-
fresh_snapshot_observed_at:
|
|
3888
|
-
safe_error_code:
|
|
3889
|
-
state_changed_at:
|
|
3890
|
-
last_error_at:
|
|
3891
|
-
attempt_count:
|
|
3892
|
-
last_attempt_at:
|
|
3893
|
-
wake_epoch:
|
|
3894
|
-
last_completed_at:
|
|
3895
|
-
lease_owner:
|
|
3896
|
-
lease_acquired_at:
|
|
3897
|
-
lease_expires_at:
|
|
3898
|
-
created_at:
|
|
3899
|
-
updated_at:
|
|
3900
|
-
}), Co =
|
|
3901
|
-
canonical_project_identity:
|
|
3902
|
-
generation:
|
|
3903
|
-
step_key:
|
|
3904
|
-
effect_id:
|
|
3905
|
-
payload_digest:
|
|
3906
|
-
status:
|
|
3907
|
-
attempt_count:
|
|
3908
|
-
started_at:
|
|
3909
|
-
completed_at:
|
|
3910
|
-
last_attempt_at:
|
|
3911
|
-
safe_error_code:
|
|
3912
|
-
error_at:
|
|
3913
|
-
lease_owner:
|
|
3914
|
-
lease_acquired_at:
|
|
3915
|
-
lease_expires_at:
|
|
3916
|
-
created_at:
|
|
3917
|
-
updated_at:
|
|
3875
|
+
x({ columns: [e.source_operation_id, e.canonical_project_identity] }),
|
|
3876
|
+
y("idx_recipient_managed_projects_identity_status").on(e.recipient_identity_id, e.status),
|
|
3877
|
+
y("idx_recipient_managed_projects_scope_authority").on(e.managed_scope_id, e.coordinator_id, e.group_id, e.status)
|
|
3878
|
+
]), So = S("recipient_policy_authority_states", {
|
|
3879
|
+
canonical_project_identity: C("canonical_project_identity").primaryKey(),
|
|
3880
|
+
authority_state: C("authority_state").notNull().default("legacy"),
|
|
3881
|
+
generation: b("generation").notNull().default(0),
|
|
3882
|
+
desired_devices_digest: C("desired_devices_digest"),
|
|
3883
|
+
current_devices_digest: C("current_devices_digest"),
|
|
3884
|
+
stable_parity_evidence_digest: C("stable_parity_evidence_digest"),
|
|
3885
|
+
stable_parity_passed_at: C("stable_parity_passed_at"),
|
|
3886
|
+
fresh_snapshot_fingerprint: C("fresh_snapshot_fingerprint"),
|
|
3887
|
+
fresh_snapshot_observed_at: C("fresh_snapshot_observed_at"),
|
|
3888
|
+
safe_error_code: C("safe_error_code"),
|
|
3889
|
+
state_changed_at: C("state_changed_at").notNull(),
|
|
3890
|
+
last_error_at: C("last_error_at"),
|
|
3891
|
+
attempt_count: b("attempt_count").notNull().default(0),
|
|
3892
|
+
last_attempt_at: C("last_attempt_at"),
|
|
3893
|
+
wake_epoch: b("wake_epoch").notNull().default(0),
|
|
3894
|
+
last_completed_at: C("last_completed_at"),
|
|
3895
|
+
lease_owner: C("lease_owner"),
|
|
3896
|
+
lease_acquired_at: C("lease_acquired_at"),
|
|
3897
|
+
lease_expires_at: C("lease_expires_at"),
|
|
3898
|
+
created_at: C("created_at").notNull(),
|
|
3899
|
+
updated_at: C("updated_at").notNull()
|
|
3900
|
+
}), Co = S("recipient_policy_reconciliation_steps", {
|
|
3901
|
+
canonical_project_identity: C("canonical_project_identity").notNull(),
|
|
3902
|
+
generation: b("generation").notNull(),
|
|
3903
|
+
step_key: C("step_key").notNull(),
|
|
3904
|
+
effect_id: C("effect_id").notNull(),
|
|
3905
|
+
payload_digest: C("payload_digest").notNull(),
|
|
3906
|
+
status: C("status").notNull().default("pending"),
|
|
3907
|
+
attempt_count: b("attempt_count").notNull().default(0),
|
|
3908
|
+
started_at: C("started_at"),
|
|
3909
|
+
completed_at: C("completed_at"),
|
|
3910
|
+
last_attempt_at: C("last_attempt_at"),
|
|
3911
|
+
safe_error_code: C("safe_error_code"),
|
|
3912
|
+
error_at: C("error_at"),
|
|
3913
|
+
lease_owner: C("lease_owner"),
|
|
3914
|
+
lease_acquired_at: C("lease_acquired_at"),
|
|
3915
|
+
lease_expires_at: C("lease_expires_at"),
|
|
3916
|
+
created_at: C("created_at").notNull(),
|
|
3917
|
+
updated_at: C("updated_at").notNull()
|
|
3918
3918
|
}, (e) => [
|
|
3919
|
-
|
|
3919
|
+
x({ columns: [
|
|
3920
3920
|
e.canonical_project_identity,
|
|
3921
3921
|
e.generation,
|
|
3922
3922
|
e.step_key
|
|
3923
3923
|
] }),
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
]), wo =
|
|
3928
|
-
canonical_project_identity:
|
|
3929
|
-
scope_id:
|
|
3930
|
-
device_id:
|
|
3931
|
-
generation:
|
|
3932
|
-
reason_code:
|
|
3933
|
-
created_at:
|
|
3934
|
-
updated_at:
|
|
3935
|
-
}, (e) => [
|
|
3924
|
+
w("idx_recipient_policy_reconciliation_steps_effect").on(e.effect_id),
|
|
3925
|
+
y("idx_recipient_policy_reconciliation_steps_status").on(e.canonical_project_identity, e.status),
|
|
3926
|
+
y("idx_recipient_policy_reconciliation_steps_pending_refresh").on(e.canonical_project_identity, e.generation, e.step_key).where(v`${e.status} IN ('pending', 'running', 'failed') AND ${e.step_key} GLOB 'refresh-after-revocations-v2:*'`)
|
|
3927
|
+
]), wo = S("recipient_policy_deny_overlays", {
|
|
3928
|
+
canonical_project_identity: C("canonical_project_identity").notNull(),
|
|
3929
|
+
scope_id: C("scope_id").notNull(),
|
|
3930
|
+
device_id: C("device_id").notNull(),
|
|
3931
|
+
generation: b("generation").notNull(),
|
|
3932
|
+
reason_code: C("reason_code").notNull(),
|
|
3933
|
+
created_at: C("created_at").notNull(),
|
|
3934
|
+
updated_at: C("updated_at").notNull()
|
|
3935
|
+
}, (e) => [x({ columns: [
|
|
3936
3936
|
e.canonical_project_identity,
|
|
3937
3937
|
e.scope_id,
|
|
3938
3938
|
e.device_id
|
|
3939
|
-
] }),
|
|
3940
|
-
boundary_scope_id:
|
|
3941
|
-
source_scope_id:
|
|
3942
|
-
additional_source_scope_ids_json:
|
|
3943
|
-
state:
|
|
3944
|
-
generation:
|
|
3945
|
-
hold_cleared_generation:
|
|
3946
|
-
hold_cleared_reason:
|
|
3947
|
-
hold_cleared_at:
|
|
3948
|
-
hold_withdrawn_generation:
|
|
3949
|
-
hold_withdrawn_device_ids_json:
|
|
3950
|
-
created_at:
|
|
3951
|
-
updated_at:
|
|
3952
|
-
}), Eo =
|
|
3953
|
-
scope_id:
|
|
3954
|
-
canonical_project_identity:
|
|
3955
|
-
group_id:
|
|
3956
|
-
withdrawn_at:
|
|
3939
|
+
] }), y("idx_recipient_policy_deny_overlays_scope_device").on(e.scope_id, e.device_id)]), To = S("project_boundary_migrations", {
|
|
3940
|
+
boundary_scope_id: C("boundary_scope_id").primaryKey(),
|
|
3941
|
+
source_scope_id: C("source_scope_id").notNull(),
|
|
3942
|
+
additional_source_scope_ids_json: C("additional_source_scope_ids_json").notNull().default("[]"),
|
|
3943
|
+
state: C("state").notNull(),
|
|
3944
|
+
generation: b("generation").notNull(),
|
|
3945
|
+
hold_cleared_generation: b("hold_cleared_generation"),
|
|
3946
|
+
hold_cleared_reason: C("hold_cleared_reason"),
|
|
3947
|
+
hold_cleared_at: C("hold_cleared_at"),
|
|
3948
|
+
hold_withdrawn_generation: b("hold_withdrawn_generation"),
|
|
3949
|
+
hold_withdrawn_device_ids_json: C("hold_withdrawn_device_ids_json"),
|
|
3950
|
+
created_at: C("created_at").notNull(),
|
|
3951
|
+
updated_at: C("updated_at").notNull()
|
|
3952
|
+
}), Eo = S("project_scope_withdrawals", {
|
|
3953
|
+
scope_id: C("scope_id").primaryKey(),
|
|
3954
|
+
canonical_project_identity: C("canonical_project_identity").notNull(),
|
|
3955
|
+
group_id: C("group_id").notNull(),
|
|
3956
|
+
withdrawn_at: C("withdrawn_at").notNull()
|
|
3957
3957
|
}), Do = {
|
|
3958
3958
|
deviceIdentityBindingCommits: mo,
|
|
3959
3959
|
deviceIdentityBindingAudit: ho,
|
|
@@ -4040,44 +4040,44 @@ function Ao(e) {
|
|
|
4040
4040
|
return null;
|
|
4041
4041
|
}
|
|
4042
4042
|
}
|
|
4043
|
-
function
|
|
4043
|
+
function jo(e) {
|
|
4044
4044
|
return e.trim().replaceAll("\\", "/").replace(/\/+$/u, "") || e.trim();
|
|
4045
4045
|
}
|
|
4046
|
-
function
|
|
4046
|
+
function Mo(e, t) {
|
|
4047
4047
|
let n = e.trim();
|
|
4048
4048
|
if (!n) return null;
|
|
4049
4049
|
if (/^[a-z][a-z0-9+.-]*:\/\//iu.test(n)) try {
|
|
4050
4050
|
let e = new URL(n);
|
|
4051
|
-
return (e.protocol === "http:" || e.protocol === "https:") && (e.username = ""), e.password = "", e.search = "", e.hash = "",
|
|
4051
|
+
return (e.protocol === "http:" || e.protocol === "https:") && (e.username = ""), e.password = "", e.search = "", e.hash = "", jo(e.toString());
|
|
4052
4052
|
} catch {
|
|
4053
4053
|
return null;
|
|
4054
4054
|
}
|
|
4055
|
-
if (/^[A-Za-z]:[\\/]/u.test(n) || !n.includes(":")) return
|
|
4055
|
+
if (/^[A-Za-z]:[\\/]/u.test(n) || !n.includes(":")) return jo(_(t, n));
|
|
4056
4056
|
let r = n.match(/^((?:[^/@:]+@)?[^/:]+):(.+)$/u);
|
|
4057
|
-
return !r?.[1] || !r[2] ? null : `${r[1]}:${
|
|
4057
|
+
return !r?.[1] || !r[2] ? null : `${r[1]}:${jo(r[2])}`;
|
|
4058
4058
|
}
|
|
4059
|
-
function
|
|
4059
|
+
function No(e) {
|
|
4060
4060
|
let t = e.replaceAll("\\", "/");
|
|
4061
4061
|
for (; t.endsWith("/");) t = t.slice(0, -1);
|
|
4062
4062
|
if (!t) return "";
|
|
4063
4063
|
let n = t.split("/");
|
|
4064
4064
|
return n[n.length - 1] ?? "";
|
|
4065
4065
|
}
|
|
4066
|
-
function
|
|
4066
|
+
function Po(e) {
|
|
4067
4067
|
return e.replaceAll("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_");
|
|
4068
4068
|
}
|
|
4069
|
-
function
|
|
4069
|
+
function Fo(e, t) {
|
|
4070
4070
|
let n = t.trim();
|
|
4071
4071
|
if (!n) return {
|
|
4072
4072
|
clause: "",
|
|
4073
4073
|
params: []
|
|
4074
4074
|
};
|
|
4075
|
-
let r = /[\\/]/.test(n) ?
|
|
4075
|
+
let r = /[\\/]/.test(n) ? No(n) : n;
|
|
4076
4076
|
if (!r) return {
|
|
4077
4077
|
clause: "",
|
|
4078
4078
|
params: []
|
|
4079
4079
|
};
|
|
4080
|
-
let i =
|
|
4080
|
+
let i = Po(r);
|
|
4081
4081
|
return {
|
|
4082
4082
|
clause: `(${e} = ? OR ${e} LIKE ? ESCAPE '\\' OR ${e} LIKE ? ESCAPE '\\')`,
|
|
4083
4083
|
params: [
|
|
@@ -4087,25 +4087,25 @@ function Po(e, t) {
|
|
|
4087
4087
|
]
|
|
4088
4088
|
};
|
|
4089
4089
|
}
|
|
4090
|
-
function
|
|
4091
|
-
return
|
|
4090
|
+
function Io(e) {
|
|
4091
|
+
return Fo("sessions.project", e);
|
|
4092
4092
|
}
|
|
4093
|
-
function
|
|
4093
|
+
function Lo(e, t) {
|
|
4094
4094
|
if (!e) return !0;
|
|
4095
4095
|
if (!t) return !1;
|
|
4096
4096
|
let n = e.trim().replaceAll("\\", "/");
|
|
4097
4097
|
if (!n) return !0;
|
|
4098
|
-
let r = n.includes("/") ?
|
|
4098
|
+
let r = n.includes("/") ? No(n) : n, i = t.replaceAll("\\", "/");
|
|
4099
4099
|
return i === r || i.endsWith(`/${r}`);
|
|
4100
4100
|
}
|
|
4101
|
-
function
|
|
4101
|
+
function Ro(e) {
|
|
4102
4102
|
let t = _(e);
|
|
4103
4103
|
for (;;) {
|
|
4104
4104
|
let e = _(t, ".git");
|
|
4105
4105
|
if (p(e)) {
|
|
4106
|
-
let n =
|
|
4106
|
+
let n = zo(t, e);
|
|
4107
4107
|
if (!n) return t;
|
|
4108
|
-
let r =
|
|
4108
|
+
let r = Bo(n);
|
|
4109
4109
|
return r.isLinkedWorktree && _e(r.commonDirectory) === ".git" ? h(r.commonDirectory) : t;
|
|
4110
4110
|
}
|
|
4111
4111
|
let n = h(t);
|
|
@@ -4113,7 +4113,7 @@ function Lo(e) {
|
|
|
4113
4113
|
t = n;
|
|
4114
4114
|
}
|
|
4115
4115
|
}
|
|
4116
|
-
function
|
|
4116
|
+
function zo(e, t) {
|
|
4117
4117
|
try {
|
|
4118
4118
|
let n = ce(t);
|
|
4119
4119
|
if (n.isDirectory()) return t;
|
|
@@ -4124,7 +4124,7 @@ function Ro(e, t) {
|
|
|
4124
4124
|
return null;
|
|
4125
4125
|
}
|
|
4126
4126
|
}
|
|
4127
|
-
function
|
|
4127
|
+
function Bo(e) {
|
|
4128
4128
|
try {
|
|
4129
4129
|
let t = m(_(e, "commondir"), "utf8").trim();
|
|
4130
4130
|
if (t) return {
|
|
@@ -4137,9 +4137,9 @@ function zo(e) {
|
|
|
4137
4137
|
isLinkedWorktree: !1
|
|
4138
4138
|
};
|
|
4139
4139
|
}
|
|
4140
|
-
function
|
|
4140
|
+
function Vo(e, t) {
|
|
4141
4141
|
try {
|
|
4142
|
-
return
|
|
4142
|
+
return Mo(be("git", [
|
|
4143
4143
|
"config",
|
|
4144
4144
|
"--file",
|
|
4145
4145
|
_(e, "config"),
|
|
@@ -4159,14 +4159,14 @@ function Bo(e, t) {
|
|
|
4159
4159
|
return null;
|
|
4160
4160
|
}
|
|
4161
4161
|
}
|
|
4162
|
-
function
|
|
4162
|
+
function Ho(e) {
|
|
4163
4163
|
let t = _(e);
|
|
4164
4164
|
for (;;) {
|
|
4165
4165
|
let e = _(t, ".git");
|
|
4166
4166
|
if (p(e)) {
|
|
4167
|
-
let n =
|
|
4167
|
+
let n = zo(t, e);
|
|
4168
4168
|
if (!n) return null;
|
|
4169
|
-
let r =
|
|
4169
|
+
let r = Bo(n), { commonDirectory: i } = r, a = jo(i), o = r.isLinkedWorktree && _e(a) === ".git" ? h(i) : t, s = Vo(i, o);
|
|
4170
4170
|
return s ? {
|
|
4171
4171
|
identity: s,
|
|
4172
4172
|
root: o,
|
|
@@ -4182,12 +4182,12 @@ function Vo(e) {
|
|
|
4182
4182
|
t = n;
|
|
4183
4183
|
}
|
|
4184
4184
|
}
|
|
4185
|
-
function
|
|
4185
|
+
function Uo(e, t) {
|
|
4186
4186
|
if (t != null) return t.trim() || null;
|
|
4187
|
-
let n =
|
|
4187
|
+
let n = Ro(e);
|
|
4188
4188
|
return _e(n || _(e));
|
|
4189
4189
|
}
|
|
4190
|
-
function
|
|
4190
|
+
function Wo(e) {
|
|
4191
4191
|
let t = _(e);
|
|
4192
4192
|
for (;;) {
|
|
4193
4193
|
if (p(_(t, ".git"))) return t;
|
|
@@ -4198,7 +4198,7 @@ function Uo(e) {
|
|
|
4198
4198
|
}
|
|
4199
4199
|
//#endregion
|
|
4200
4200
|
//#region src/recipient-policy-deny-overlay.ts
|
|
4201
|
-
function
|
|
4201
|
+
function Go(e) {
|
|
4202
4202
|
return {
|
|
4203
4203
|
canonicalProjectIdentity: String(e.canonical_project_identity),
|
|
4204
4204
|
scopeId: String(e.scope_id),
|
|
@@ -4209,50 +4209,50 @@ function Wo(e) {
|
|
|
4209
4209
|
updatedAt: String(e.updated_at)
|
|
4210
4210
|
};
|
|
4211
4211
|
}
|
|
4212
|
-
function
|
|
4212
|
+
function Ko(e, t) {
|
|
4213
4213
|
let n = e.prepare("SELECT * FROM recipient_policy_deny_overlays\n WHERE scope_id = ? AND device_id = ?\n ORDER BY canonical_project_identity\n LIMIT 1").get(t.scopeId, t.deviceId);
|
|
4214
|
-
return n ?
|
|
4214
|
+
return n ? Go(n) : null;
|
|
4215
4215
|
}
|
|
4216
4216
|
//#endregion
|
|
4217
4217
|
//#region src/scope-membership-snapshot.ts
|
|
4218
|
-
function
|
|
4218
|
+
function qo(e, t) {
|
|
4219
4219
|
if (!e || typeof e != "object" || Array.isArray(e)) throw Error("Invalid current scope snapshot.");
|
|
4220
4220
|
let n = e;
|
|
4221
4221
|
if (n[t] !== 1 || !Array.isArray(n.items)) throw Error("Current scope snapshot version 1 and items required.");
|
|
4222
4222
|
return n;
|
|
4223
4223
|
}
|
|
4224
|
-
function
|
|
4224
|
+
function Jo(e, t) {
|
|
4225
4225
|
r(e, n);
|
|
4226
4226
|
let i = e;
|
|
4227
4227
|
if (c(i, t)) throw Error("Invalid scope source or status.");
|
|
4228
4228
|
return i;
|
|
4229
4229
|
}
|
|
4230
|
-
function
|
|
4231
|
-
let n =
|
|
4230
|
+
function Yo(e, t) {
|
|
4231
|
+
let n = qo(e, "version").items.map((e) => Jo(e, t));
|
|
4232
4232
|
if (new Set(n.map((e) => e.scope_id)).size !== n.length) throw Error("Duplicate scope in catalog.");
|
|
4233
4233
|
return n;
|
|
4234
4234
|
}
|
|
4235
|
-
function
|
|
4235
|
+
function Xo(e, t) {
|
|
4236
4236
|
return Object.fromEntries(t.map((t) => [t, e[t]]));
|
|
4237
4237
|
}
|
|
4238
|
-
function
|
|
4238
|
+
function Zo(n, i) {
|
|
4239
4239
|
if (!n || typeof n != "object" || Array.isArray(n)) throw Error("Invalid current scope member.");
|
|
4240
4240
|
let a = n;
|
|
4241
4241
|
r(a.membership, s), r(a.enrollment, t);
|
|
4242
4242
|
let { membership: o, enrollment: c } = a, l = e(c.public_key);
|
|
4243
4243
|
if (!ee(i, o) || c.enabled !== 1 || c.group_id !== i.group_id || c.device_id !== o.device_id || l.kind !== "ed25519" || d("sha256").update(l.blob).digest("hex") !== a.key_id) throw Error("Current scope member evidence mismatch.");
|
|
4244
4244
|
return {
|
|
4245
|
-
membership:
|
|
4246
|
-
enrollment:
|
|
4245
|
+
membership: Xo(o, s),
|
|
4246
|
+
enrollment: Xo(c, t),
|
|
4247
4247
|
key_id: a.key_id
|
|
4248
4248
|
};
|
|
4249
4249
|
}
|
|
4250
|
-
function
|
|
4251
|
-
let a =
|
|
4250
|
+
function Qo(e, t, r, i) {
|
|
4251
|
+
let a = qo(e, "authorization_version"), o = Jo(a.scope, r);
|
|
4252
4252
|
if (o.scope_id !== t.scope_id || o.membership_epoch < t.membership_epoch || o.coordinator_id !== t.coordinator_id) throw Error("Current scope snapshot source mismatch.");
|
|
4253
|
-
let s = a.items.map((e) =>
|
|
4253
|
+
let s = a.items.map((e) => Zo(e, o));
|
|
4254
4254
|
if (new Set(s.map((e) => e.membership.device_id)).size !== s.length) throw Error("Duplicate device in current scope snapshot.");
|
|
4255
|
-
let c =
|
|
4255
|
+
let c = Xo(o, n);
|
|
4256
4256
|
return {
|
|
4257
4257
|
scope: {
|
|
4258
4258
|
...c,
|
|
@@ -4273,7 +4273,7 @@ function Zo(e, t, r, i) {
|
|
|
4273
4273
|
}
|
|
4274
4274
|
//#endregion
|
|
4275
4275
|
//#region src/scope-membership-evidence.ts
|
|
4276
|
-
var
|
|
4276
|
+
var $o = [
|
|
4277
4277
|
"scope_id",
|
|
4278
4278
|
"kind",
|
|
4279
4279
|
"authority_type",
|
|
@@ -4283,7 +4283,7 @@ var Qo = [
|
|
|
4283
4283
|
"membership_epoch",
|
|
4284
4284
|
"manifest_hash",
|
|
4285
4285
|
"status"
|
|
4286
|
-
],
|
|
4286
|
+
], es = [
|
|
4287
4287
|
"scope_id",
|
|
4288
4288
|
"device_id",
|
|
4289
4289
|
"role",
|
|
@@ -4295,28 +4295,28 @@ var Qo = [
|
|
|
4295
4295
|
"manifest_hash",
|
|
4296
4296
|
"signed_manifest_json"
|
|
4297
4297
|
];
|
|
4298
|
-
function
|
|
4298
|
+
function ts(e) {
|
|
4299
4299
|
return !!e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get("scope_membership_authorization_evidence");
|
|
4300
4300
|
}
|
|
4301
|
-
function
|
|
4301
|
+
function ns(e) {
|
|
4302
4302
|
e.exec("CREATE TABLE IF NOT EXISTS scope_membership_authorization_evidence (\n coordinator_id TEXT NOT NULL, group_id TEXT NOT NULL,\n scope_id TEXT NOT NULL, device_id TEXT NOT NULL, evidence_json TEXT NOT NULL,\n PRIMARY KEY (coordinator_id, group_id, scope_id, device_id)\n )");
|
|
4303
4303
|
}
|
|
4304
|
-
function
|
|
4304
|
+
function rs(e, t, n) {
|
|
4305
4305
|
return n.every((n) => e[n] === t[n]);
|
|
4306
4306
|
}
|
|
4307
|
-
function
|
|
4307
|
+
function is(e, t, n) {
|
|
4308
4308
|
let r = e.memberships[0];
|
|
4309
|
-
return r ?
|
|
4309
|
+
return r ? rs(e.scope, t, $o) && e.memberships.length === 1 && rs(r, n, es) : !1;
|
|
4310
4310
|
}
|
|
4311
|
-
function
|
|
4311
|
+
function as(e, t) {
|
|
4312
4312
|
try {
|
|
4313
|
-
let n = JSON.parse(e), r =
|
|
4313
|
+
let n = JSON.parse(e), r = Qo(n, n.scope, t.groupId, t.coordinatorId);
|
|
4314
4314
|
return r.evidence.items.length === 1 ? r : null;
|
|
4315
4315
|
} catch {
|
|
4316
4316
|
return null;
|
|
4317
4317
|
}
|
|
4318
4318
|
}
|
|
4319
|
-
function
|
|
4319
|
+
function os(e, t) {
|
|
4320
4320
|
let n = e.evidence.items[t];
|
|
4321
4321
|
if (!n) throw Error("Scope authorization evidence unavailable.");
|
|
4322
4322
|
return {
|
|
@@ -4324,61 +4324,81 @@ function as(e, t) {
|
|
|
4324
4324
|
items: [n]
|
|
4325
4325
|
};
|
|
4326
4326
|
}
|
|
4327
|
-
function
|
|
4327
|
+
function ss(e, t, n, r) {
|
|
4328
4328
|
if (r.removalOnly) {
|
|
4329
|
-
|
|
4329
|
+
ls(e, t, n);
|
|
4330
4330
|
return;
|
|
4331
4331
|
}
|
|
4332
|
-
|
|
4332
|
+
ns(e), e.prepare("DELETE FROM scope_membership_authorization_evidence WHERE coordinator_id = ? AND group_id = ?").run(n.coordinatorId, n.groupId);
|
|
4333
4333
|
let i = e.prepare("INSERT INTO scope_membership_authorization_evidence\n (coordinator_id, group_id, scope_id, device_id, evidence_json) VALUES (?, ?, ?, ?, ?)");
|
|
4334
|
-
for (let e of t) for (let [t, r] of e.memberships.entries()) i.run(n.coordinatorId, n.groupId, e.scope.scope_id, r.device_id, JSON.stringify(
|
|
4334
|
+
for (let e of t) for (let [t, r] of e.memberships.entries()) i.run(n.coordinatorId, n.groupId, e.scope.scope_id, r.device_id, JSON.stringify(os(e, t)));
|
|
4335
4335
|
}
|
|
4336
|
-
function
|
|
4336
|
+
function cs(e, t) {
|
|
4337
4337
|
let n = e.evidence.items[0], r = t.evidence.items[0], i = t.memberships[0];
|
|
4338
|
-
return !n || !r || !i ? !1 :
|
|
4338
|
+
return !n || !r || !i ? !1 : is(e, t.scope, i) && e.sourceCoordinatorId === t.sourceCoordinatorId && n.key_id === r.key_id && rs(n.membership, r.membership, es) && rs(n.enrollment, r.enrollment, [
|
|
4339
4339
|
"group_id",
|
|
4340
4340
|
"device_id",
|
|
4341
4341
|
"fingerprint",
|
|
4342
4342
|
"enabled"
|
|
4343
4343
|
]);
|
|
4344
4344
|
}
|
|
4345
|
-
function
|
|
4346
|
-
if (!
|
|
4345
|
+
function ls(e, t, n) {
|
|
4346
|
+
if (!ts(e)) return;
|
|
4347
4347
|
let r = e.prepare("SELECT scope_id, device_id, evidence_json\n FROM scope_membership_authorization_evidence WHERE coordinator_id = ? AND group_id = ?").all(n.coordinatorId, n.groupId), i = e.prepare("DELETE FROM scope_membership_authorization_evidence\n WHERE coordinator_id = ? AND group_id = ? AND scope_id = ? AND device_id = ?");
|
|
4348
4348
|
for (let e of r) {
|
|
4349
|
-
let r = t.find((t) => t.scope.scope_id === e.scope_id), a = r?.memberships.findIndex((t) => t.device_id === e.device_id) ?? -1, o =
|
|
4350
|
-
(!o || !s || !
|
|
4349
|
+
let r = t.find((t) => t.scope.scope_id === e.scope_id), a = r?.memberships.findIndex((t) => t.device_id === e.device_id) ?? -1, o = as(e.evidence_json, n), s = r && a >= 0 ? Qo(os(r, a), r.evidence.scope, n.groupId, n.coordinatorId) : null;
|
|
4350
|
+
(!o || !s || !cs(o, s)) && i.run(n.coordinatorId, n.groupId, e.scope_id, e.device_id);
|
|
4351
4351
|
}
|
|
4352
4352
|
}
|
|
4353
|
-
|
|
4353
|
+
var X = "scope_membership_removal_state";
|
|
4354
|
+
function us(e) {
|
|
4355
|
+
return e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(X) ? e.prepare(`SELECT generation FROM ${X} WHERE id = 1`).get()?.generation ?? 0 : 0;
|
|
4356
|
+
}
|
|
4357
|
+
function ds(e) {
|
|
4358
|
+
e.exec(`CREATE TABLE IF NOT EXISTS ${X} (
|
|
4359
|
+
id INTEGER PRIMARY KEY CHECK (id = 1),
|
|
4360
|
+
generation INTEGER NOT NULL
|
|
4361
|
+
)`), e.prepare(`INSERT INTO ${X}(id, generation) VALUES (1, 1)
|
|
4362
|
+
ON CONFLICT(id) DO UPDATE SET generation = generation + 1`).run();
|
|
4363
|
+
}
|
|
4364
|
+
function fs(e, t) {
|
|
4365
|
+
if (t.length === 0 || (ds(e), !ts(e))) return 0;
|
|
4366
|
+
let n = e.prepare("DELETE FROM scope_membership_authorization_evidence WHERE device_id = ?");
|
|
4367
|
+
return t.reduce((e, t) => e + n.run(t).changes, 0);
|
|
4368
|
+
}
|
|
4369
|
+
function ps(t, n, r, a, o) {
|
|
4354
4370
|
try {
|
|
4355
|
-
if (!n.coordinator_id || !n.group_id || !
|
|
4356
|
-
let
|
|
4371
|
+
if (!n.coordinator_id || !n.group_id || !ts(t)) return null;
|
|
4372
|
+
let s = {
|
|
4357
4373
|
coordinatorId: n.coordinator_id,
|
|
4358
4374
|
groupId: n.group_id
|
|
4359
|
-
},
|
|
4360
|
-
if (!
|
|
4361
|
-
let
|
|
4362
|
-
if (!
|
|
4363
|
-
if (
|
|
4364
|
-
let t = e(
|
|
4365
|
-
if (t.kind !== "ed25519" || d("sha256").update(t.blob).digest("hex") !==
|
|
4375
|
+
}, c = t.prepare("SELECT evidence_json FROM scope_membership_authorization_evidence\n WHERE coordinator_id = ? AND group_id = ? AND scope_id = ? AND device_id = ?").get(s.coordinatorId, s.groupId, n.scope_id, r.device_id), l = c && as(c.evidence_json, s);
|
|
4376
|
+
if (!l || !is(l, n, r)) return null;
|
|
4377
|
+
let u = l.evidence.items[0]?.key_id;
|
|
4378
|
+
if (!u) return null;
|
|
4379
|
+
if (a !== void 0) {
|
|
4380
|
+
let t = e(a);
|
|
4381
|
+
if (t.kind !== "ed25519" || d("sha256").update(t.blob).digest("hex") !== u) return null;
|
|
4382
|
+
}
|
|
4383
|
+
if (o !== void 0) {
|
|
4384
|
+
let e = l.evidence.items[0]?.enrollment.public_key;
|
|
4385
|
+
if (typeof e != "string" || i(e) !== o) return null;
|
|
4366
4386
|
}
|
|
4367
|
-
return
|
|
4387
|
+
return u;
|
|
4368
4388
|
} catch {
|
|
4369
4389
|
return null;
|
|
4370
4390
|
}
|
|
4371
4391
|
}
|
|
4372
4392
|
//#endregion
|
|
4373
4393
|
//#region src/scope-membership-cache-read.ts
|
|
4374
|
-
var
|
|
4394
|
+
var ms = 6e4;
|
|
4375
4395
|
function Z(e) {
|
|
4376
4396
|
return e?.trim() || null;
|
|
4377
4397
|
}
|
|
4378
|
-
function
|
|
4398
|
+
function hs(e, t) {
|
|
4379
4399
|
return e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get("scope_membership_cache_state") ? t ? e.prepare("SELECT coordinator_id, group_id, last_refresh_at, last_success_at, last_error, updated_at\n FROM scope_membership_cache_state\n WHERE coordinator_id = ? AND group_id = ?").all(t.coordinatorId, t.groupId) : e.prepare("SELECT coordinator_id, group_id, last_refresh_at, last_success_at, last_error, updated_at\n FROM scope_membership_cache_state\n ORDER BY coordinator_id ASC, group_id ASC").all() : [];
|
|
4380
4400
|
}
|
|
4381
|
-
function
|
|
4401
|
+
function gs(e, t) {
|
|
4382
4402
|
if (e.length === 0) return "unknown";
|
|
4383
4403
|
if (e.some((e) => Z(e.last_error) != null)) return "stale";
|
|
4384
4404
|
let n = t.maxAgeMs ?? 6e4, r = (t.now ?? /* @__PURE__ */ new Date()).getTime();
|
|
@@ -4387,7 +4407,7 @@ function fs(e, t) {
|
|
|
4387
4407
|
return !Number.isFinite(t) || r - t > n;
|
|
4388
4408
|
}) ? "stale" : "fresh";
|
|
4389
4409
|
}
|
|
4390
|
-
function
|
|
4410
|
+
function _s(e) {
|
|
4391
4411
|
return !e.scope_label || !e.scope_kind || !e.scope_authority_type ? null : {
|
|
4392
4412
|
scope_id: e.scope_id,
|
|
4393
4413
|
label: e.scope_label,
|
|
@@ -4403,7 +4423,7 @@ function ps(e) {
|
|
|
4403
4423
|
updated_at: e.scope_updated_at ?? e.updated_at
|
|
4404
4424
|
};
|
|
4405
4425
|
}
|
|
4406
|
-
function
|
|
4426
|
+
function vs(e, t, n) {
|
|
4407
4427
|
let r = n ? " AND coordinator_id = ? AND group_id = ?" : "", i = n ? [
|
|
4408
4428
|
t,
|
|
4409
4429
|
n.coordinatorId,
|
|
@@ -4415,7 +4435,7 @@ function ms(e, t, n) {
|
|
|
4415
4435
|
WHERE scope_id = ?${r}
|
|
4416
4436
|
LIMIT 1`).get(...i) ?? null;
|
|
4417
4437
|
}
|
|
4418
|
-
function
|
|
4438
|
+
function ys(e) {
|
|
4419
4439
|
return {
|
|
4420
4440
|
scope_id: e.scope_id,
|
|
4421
4441
|
device_id: e.device_id,
|
|
@@ -4430,7 +4450,7 @@ function hs(e) {
|
|
|
4430
4450
|
updated_at: e.updated_at
|
|
4431
4451
|
};
|
|
4432
4452
|
}
|
|
4433
|
-
function
|
|
4453
|
+
function bs(e) {
|
|
4434
4454
|
return `SELECT
|
|
4435
4455
|
sm.scope_id,
|
|
4436
4456
|
sm.device_id,
|
|
@@ -4458,50 +4478,70 @@ function gs(e) {
|
|
|
4458
4478
|
LEFT JOIN replication_scopes rs ON rs.scope_id = sm.scope_id
|
|
4459
4479
|
${e}`;
|
|
4460
4480
|
}
|
|
4461
|
-
function
|
|
4481
|
+
function xs(e, t) {
|
|
4462
4482
|
let n = Z(e?.coordinator_id) ?? t?.coordinatorId, r = Z(e?.group_id) ?? t?.groupId;
|
|
4463
4483
|
return n && r ? {
|
|
4464
4484
|
coordinatorId: n,
|
|
4465
4485
|
groupId: r
|
|
4466
4486
|
} : null;
|
|
4467
4487
|
}
|
|
4468
|
-
function
|
|
4488
|
+
function Ss(e) {
|
|
4469
4489
|
let t = Z(e?.coordinator_id), n = Z(e?.group_id);
|
|
4470
4490
|
return t && n ? {
|
|
4471
4491
|
coordinatorId: t,
|
|
4472
4492
|
groupId: n
|
|
4473
4493
|
} : null;
|
|
4474
4494
|
}
|
|
4475
|
-
function
|
|
4495
|
+
function Cs(e, t, n = {}) {
|
|
4476
4496
|
let r = Z(t);
|
|
4477
4497
|
if (!r) throw Error("device_id is required.");
|
|
4478
4498
|
let i = [r], a = n.authority ? " AND COALESCE(sm.coordinator_id, rs.coordinator_id) = ? AND COALESCE(sm.group_id, rs.group_id) = ?" : "";
|
|
4479
4499
|
n.authority && i.push(n.authority.coordinatorId, n.authority.groupId);
|
|
4480
|
-
let o = e.prepare(`${
|
|
4500
|
+
let o = e.prepare(`${bs(`WHERE sm.device_id = ? AND sm.status = 'active' AND rs.scope_id IS NOT NULL AND rs.status = 'active' AND sm.membership_epoch >= rs.membership_epoch${a}`)} ORDER BY sm.scope_id ASC`).all(...i), s = hs(e, n.authority ?? null), c = o.filter((t) => Ko(e, {
|
|
4481
4501
|
scopeId: t.scope_id,
|
|
4482
4502
|
deviceId: r
|
|
4483
4503
|
}) == null);
|
|
4484
4504
|
return {
|
|
4485
4505
|
deviceId: r,
|
|
4486
|
-
freshness:
|
|
4506
|
+
freshness: gs(s, n),
|
|
4487
4507
|
memberships: c.map((e) => ({
|
|
4488
|
-
...
|
|
4489
|
-
scope:
|
|
4508
|
+
...ys(e),
|
|
4509
|
+
scope: _s(e)
|
|
4490
4510
|
})),
|
|
4491
4511
|
cacheStates: s
|
|
4492
4512
|
};
|
|
4493
4513
|
}
|
|
4494
|
-
function
|
|
4514
|
+
function ws(e, t) {
|
|
4495
4515
|
if (!Z(t.deviceId) || !Z(t.scopeId)) throw Error("device_id and scope_id are required.");
|
|
4496
|
-
return
|
|
4516
|
+
return js(e, t);
|
|
4497
4517
|
}
|
|
4498
|
-
|
|
4499
|
-
|
|
4518
|
+
var Ts = /* @__PURE__ */ new Set(["manual", "invite"]);
|
|
4519
|
+
function Es(e) {
|
|
4520
|
+
return !Ts.has(e ?? "");
|
|
4521
|
+
}
|
|
4522
|
+
function Ds(e) {
|
|
4523
|
+
return !e.authorized || Es(e.scope?.authority_type) ? e : {
|
|
4524
|
+
...e,
|
|
4525
|
+
authorized: !1,
|
|
4526
|
+
state: "not_authorized"
|
|
4527
|
+
};
|
|
4528
|
+
}
|
|
4529
|
+
function Os(e, t) {
|
|
4530
|
+
return Ds(ws(e, t));
|
|
4531
|
+
}
|
|
4532
|
+
function ks(e) {
|
|
4533
|
+
let t = e?.public_key?.trim();
|
|
4534
|
+
if (t) return { expectedPublicKey: t };
|
|
4535
|
+
let n = e?.pinned_fingerprint?.trim();
|
|
4536
|
+
return n ? { expectedFingerprint: n } : null;
|
|
4537
|
+
}
|
|
4538
|
+
function As(e, t) {
|
|
4539
|
+
let n = Ds(js(e, t));
|
|
4500
4540
|
if (!n.authorized || n.scope?.authority_type !== "coordinator") return {
|
|
4501
4541
|
...n,
|
|
4502
4542
|
keyId: null
|
|
4503
4543
|
};
|
|
4504
|
-
let r = n.membership &&
|
|
4544
|
+
let r = n.membership && ps(e, n.scope, n.membership, t.expectedPublicKey, t.expectedFingerprint);
|
|
4505
4545
|
return r ? {
|
|
4506
4546
|
...n,
|
|
4507
4547
|
keyId: r
|
|
@@ -4512,21 +4552,21 @@ function xs(e, t) {
|
|
|
4512
4552
|
keyId: null
|
|
4513
4553
|
};
|
|
4514
4554
|
}
|
|
4515
|
-
function
|
|
4555
|
+
function js(e, t) {
|
|
4516
4556
|
let n = Z(t.deviceId), r = Z(t.scopeId);
|
|
4517
4557
|
if (!n || !r) throw Error("device_id and scope_id are required.");
|
|
4518
|
-
let { membership: i, scope: o } =
|
|
4558
|
+
let { membership: i, scope: o } = Ms(e, {
|
|
4519
4559
|
...t,
|
|
4520
4560
|
deviceId: n,
|
|
4521
4561
|
scopeId: r
|
|
4522
|
-
}), s =
|
|
4562
|
+
}), s = hs(e, xs(i, t.authority ?? Ss(o))), c = a({
|
|
4523
4563
|
membershipEpoch: i?.membership_epoch ?? null,
|
|
4524
4564
|
requiredEpoch: o?.membership_epoch ?? null
|
|
4525
|
-
}), u =
|
|
4565
|
+
}), u = Ns({
|
|
4526
4566
|
membership: i,
|
|
4527
4567
|
scope: o,
|
|
4528
4568
|
epoch: c,
|
|
4529
|
-
policyDenied: !!
|
|
4569
|
+
policyDenied: !!Ko(e, {
|
|
4530
4570
|
deviceId: n,
|
|
4531
4571
|
scopeId: r
|
|
4532
4572
|
})
|
|
@@ -4540,7 +4580,7 @@ function Ss(e, t) {
|
|
|
4540
4580
|
scopeId: r,
|
|
4541
4581
|
authorized: u === "authorized",
|
|
4542
4582
|
state: u,
|
|
4543
|
-
freshness:
|
|
4583
|
+
freshness: gs(s, t),
|
|
4544
4584
|
epoch: c,
|
|
4545
4585
|
revocation: ee,
|
|
4546
4586
|
membership: i,
|
|
@@ -4548,104 +4588,104 @@ function Ss(e, t) {
|
|
|
4548
4588
|
cacheStates: s
|
|
4549
4589
|
};
|
|
4550
4590
|
}
|
|
4551
|
-
function
|
|
4591
|
+
function Ms(e, t) {
|
|
4552
4592
|
let n = t.authority ? " AND COALESCE(sm.coordinator_id, rs.coordinator_id) = ? AND COALESCE(sm.group_id, rs.group_id) = ?" : "", r = t.authority ? [
|
|
4553
4593
|
t.deviceId,
|
|
4554
4594
|
t.scopeId,
|
|
4555
4595
|
t.authority.coordinatorId,
|
|
4556
4596
|
t.authority.groupId
|
|
4557
|
-
] : [t.deviceId, t.scopeId], i = e.prepare(`${
|
|
4597
|
+
] : [t.deviceId, t.scopeId], i = e.prepare(`${bs(`WHERE sm.device_id = ? AND sm.scope_id = ?${n} LIMIT 1`)}`).get(...r);
|
|
4558
4598
|
return {
|
|
4559
|
-
membership: i ?
|
|
4560
|
-
scope: i ?
|
|
4599
|
+
membership: i ? ys(i) : null,
|
|
4600
|
+
scope: i ? _s(i) : vs(e, t.scopeId, t.authority ?? null)
|
|
4561
4601
|
};
|
|
4562
4602
|
}
|
|
4563
|
-
function
|
|
4603
|
+
function Ns(e) {
|
|
4564
4604
|
let { membership: t, scope: n, epoch: r, policyDenied: i } = e;
|
|
4565
4605
|
return i ? "policy_denied" : t ? t.status === "revoked" ? "revoked" : n?.status && n.status !== "active" ? "scope_inactive" : n ? r.stale ? "stale_epoch" : t.status === "active" ? "authorized" : "not_authorized" : "scope_unknown" : "not_authorized";
|
|
4566
4606
|
}
|
|
4567
4607
|
//#endregion
|
|
4568
4608
|
//#region src/wildcard-match.ts
|
|
4569
|
-
var
|
|
4609
|
+
var Ps = (e) => ![
|
|
4570
4610
|
"\n",
|
|
4571
4611
|
"\r",
|
|
4572
4612
|
"\u2028",
|
|
4573
4613
|
"\u2029"
|
|
4574
4614
|
].includes(e);
|
|
4575
|
-
function
|
|
4576
|
-
return e === "?" ?
|
|
4615
|
+
function Fs(e, t) {
|
|
4616
|
+
return e === "?" ? Ps(t) : e === t;
|
|
4577
4617
|
}
|
|
4578
|
-
function
|
|
4618
|
+
function Is(e, t, n) {
|
|
4579
4619
|
let r = new Uint8Array(n.length + 1);
|
|
4580
4620
|
t === "*" && (r[0] = e[0] ?? 0);
|
|
4581
4621
|
for (let i = 1; i <= n.length; i += 1) {
|
|
4582
4622
|
let a = n[i - 1] ?? "";
|
|
4583
|
-
t === "*" ? r[i] = e[i] || r[i - 1] &&
|
|
4623
|
+
t === "*" ? r[i] = e[i] || r[i - 1] && Ps(a) ? 1 : 0 : Fs(t, a) && (r[i] = e[i - 1] ?? 0);
|
|
4584
4624
|
}
|
|
4585
4625
|
return r;
|
|
4586
4626
|
}
|
|
4587
|
-
function
|
|
4627
|
+
function Ls(e, t, n) {
|
|
4588
4628
|
let r = n.unicode ? Array.from(e) : e.split(""), i = n.unicode ? Array.from(t) : t.split(""), a = new Uint8Array(r.length + 1);
|
|
4589
4629
|
a[0] = 1;
|
|
4590
|
-
for (let e of i) a =
|
|
4630
|
+
for (let e of i) a = Is(a, e, r);
|
|
4591
4631
|
return a[r.length] === 1;
|
|
4592
4632
|
}
|
|
4593
4633
|
//#endregion
|
|
4594
4634
|
//#region src/scope-resolution.ts
|
|
4595
|
-
var
|
|
4635
|
+
var Rs = "local-default", zs = "legacy-shared-review";
|
|
4596
4636
|
function Q(e) {
|
|
4597
4637
|
return e?.trim() || null;
|
|
4598
4638
|
}
|
|
4599
4639
|
function $(e) {
|
|
4600
4640
|
return e.trim().replaceAll("\\", "/").replace(/\/+$/, "") || e.trim();
|
|
4601
4641
|
}
|
|
4602
|
-
function
|
|
4642
|
+
function Bs(e) {
|
|
4603
4643
|
return $(_(e));
|
|
4604
4644
|
}
|
|
4605
|
-
function
|
|
4645
|
+
function Vs(e) {
|
|
4606
4646
|
let t = Q(e);
|
|
4607
4647
|
return t ? $(t) : null;
|
|
4608
4648
|
}
|
|
4609
|
-
function
|
|
4649
|
+
function Hs(e) {
|
|
4610
4650
|
return !/[\\/:]/.test(e);
|
|
4611
4651
|
}
|
|
4612
|
-
function
|
|
4652
|
+
function Us(e) {
|
|
4613
4653
|
return e.replace(/[*?]/g, "").length;
|
|
4614
4654
|
}
|
|
4615
|
-
function
|
|
4655
|
+
function Ws(e, t) {
|
|
4616
4656
|
let n = $(t);
|
|
4617
|
-
return !n ||
|
|
4657
|
+
return !n || Hs(n) ? !1 : /[*?]/.test(n) ? Ls(e, n, { unicode: !1 }) : e === n;
|
|
4618
4658
|
}
|
|
4619
|
-
function
|
|
4659
|
+
function Gs(e) {
|
|
4620
4660
|
return e.mapping.priority ?? 0;
|
|
4621
4661
|
}
|
|
4622
|
-
function
|
|
4662
|
+
function Ks(e) {
|
|
4623
4663
|
let t = Q(e.mapping.updated_at);
|
|
4624
4664
|
if (!t) return 0;
|
|
4625
4665
|
let n = Date.parse(t);
|
|
4626
4666
|
return Number.isFinite(n) ? n : 0;
|
|
4627
4667
|
}
|
|
4628
|
-
function
|
|
4629
|
-
return
|
|
4668
|
+
function qs(e, t) {
|
|
4669
|
+
return Gs(t) - Gs(e) || t.specificity - e.specificity || Ks(t) - Ks(e) || (t.mapping.id ?? 0) - (e.mapping.id ?? 0) || e.mapping.scope_id.localeCompare(t.mapping.scope_id);
|
|
4630
4670
|
}
|
|
4631
|
-
function
|
|
4632
|
-
return e.toSorted(
|
|
4671
|
+
function Js(e) {
|
|
4672
|
+
return e.toSorted(qs)[0] ?? null;
|
|
4633
4673
|
}
|
|
4634
|
-
function
|
|
4674
|
+
function Ys(e, t) {
|
|
4635
4675
|
let n = [t.value];
|
|
4636
4676
|
if (e.allowRepositoryCwdFallback === !1 || t.source !== "git_repository" && t.source !== "git_remote" && t.source !== "git_remote_branch") return n;
|
|
4637
4677
|
let r = o(e.cwd);
|
|
4638
|
-
return r && n.push(
|
|
4678
|
+
return r && n.push(Bs(r)), n;
|
|
4639
4679
|
}
|
|
4640
|
-
function
|
|
4680
|
+
function Xs(e, t) {
|
|
4641
4681
|
let n = [t.value];
|
|
4642
4682
|
if (e.allowRepositoryCwdFallback === !1 || t.source !== "git_repository" && t.source !== "git_remote" && t.source !== "git_remote_branch") return n;
|
|
4643
4683
|
let r = o(e.cwd);
|
|
4644
|
-
return r && n.push(
|
|
4684
|
+
return r && n.push(Bs(r)), n;
|
|
4645
4685
|
}
|
|
4646
|
-
function
|
|
4686
|
+
function Zs(e, t) {
|
|
4647
4687
|
for (let n of t) {
|
|
4648
|
-
let t =
|
|
4688
|
+
let t = Js(e.filter((e) => Vs(e.workspace_identity) === n).map((e) => ({
|
|
4649
4689
|
mapping: e,
|
|
4650
4690
|
matchedPattern: null,
|
|
4651
4691
|
specificity: n.length
|
|
@@ -4654,27 +4694,27 @@ function Hs(e, t) {
|
|
|
4654
4694
|
}
|
|
4655
4695
|
return null;
|
|
4656
4696
|
}
|
|
4657
|
-
function
|
|
4658
|
-
return
|
|
4697
|
+
function Qs(e, t) {
|
|
4698
|
+
return Js(t.flatMap((t) => e.flatMap((e) => {
|
|
4659
4699
|
if (Q(e.workspace_identity)) return [];
|
|
4660
4700
|
let n = Q(e.project_pattern);
|
|
4661
|
-
return !n || !
|
|
4701
|
+
return !n || !Ws(t, n) ? [] : [{
|
|
4662
4702
|
mapping: e,
|
|
4663
4703
|
matchedPattern: $(n),
|
|
4664
|
-
specificity:
|
|
4704
|
+
specificity: Us(n)
|
|
4665
4705
|
}];
|
|
4666
4706
|
})));
|
|
4667
4707
|
}
|
|
4668
|
-
function
|
|
4708
|
+
function $s(e, t) {
|
|
4669
4709
|
let n = [...t].map($), r = /* @__PURE__ */ new Set();
|
|
4670
4710
|
for (let t of e) {
|
|
4671
4711
|
if (Q(t.workspace_identity)) continue;
|
|
4672
4712
|
let e = Q(t.project_pattern);
|
|
4673
|
-
!e || !n.some((t) =>
|
|
4713
|
+
!e || !n.some((t) => Ws(t, e)) || r.add(t.scope_id);
|
|
4674
4714
|
}
|
|
4675
4715
|
return r;
|
|
4676
4716
|
}
|
|
4677
|
-
function
|
|
4717
|
+
function ec(e) {
|
|
4678
4718
|
let t = u(e), n = Q(e.explicitScopeId);
|
|
4679
4719
|
if (n) return {
|
|
4680
4720
|
scopeId: n,
|
|
@@ -4690,7 +4730,7 @@ function Gs(e) {
|
|
|
4690
4730
|
mapping: null,
|
|
4691
4731
|
matchedPattern: null
|
|
4692
4732
|
};
|
|
4693
|
-
let r = e.mappings ?? [], i =
|
|
4733
|
+
let r = e.mappings ?? [], i = Zs(r, Ys(e, t));
|
|
4694
4734
|
if (i) return {
|
|
4695
4735
|
scopeId: i.mapping.scope_id,
|
|
4696
4736
|
reason: "exact_mapping",
|
|
@@ -4698,7 +4738,7 @@ function Gs(e) {
|
|
|
4698
4738
|
mapping: i.mapping,
|
|
4699
4739
|
matchedPattern: null
|
|
4700
4740
|
};
|
|
4701
|
-
let a =
|
|
4741
|
+
let a = Qs(r, Xs(e, t));
|
|
4702
4742
|
return a ? {
|
|
4703
4743
|
scopeId: a.mapping.scope_id,
|
|
4704
4744
|
reason: "pattern_mapping",
|
|
@@ -4713,18 +4753,18 @@ function Gs(e) {
|
|
|
4713
4753
|
matchedPattern: null
|
|
4714
4754
|
};
|
|
4715
4755
|
}
|
|
4716
|
-
function
|
|
4756
|
+
function tc(e, t) {
|
|
4717
4757
|
if (t.expectedPublicKey != null) return t.expectedPublicKey;
|
|
4718
4758
|
if (e.some((e) => e.scope_id != null && e.authority_type === "coordinator")) return t.loadExpectedPublicKey?.();
|
|
4719
4759
|
}
|
|
4720
|
-
function
|
|
4760
|
+
function nc(e, t, n = {}) {
|
|
4721
4761
|
let r = /* @__PURE__ */ new Set([
|
|
4722
4762
|
"",
|
|
4723
|
-
|
|
4724
|
-
|
|
4763
|
+
Rs,
|
|
4764
|
+
zs
|
|
4725
4765
|
]), i = e.prepare("SELECT scope_id\n FROM replication_scopes\n WHERE status = 'active' AND authority_type = 'local'").all();
|
|
4726
4766
|
for (let e of i) e.scope_id != null && r.add(e.scope_id);
|
|
4727
|
-
let a = e.prepare("SELECT sm.scope_id AS scope_id, rs.authority_type\n FROM scope_memberships sm\n JOIN replication_scopes rs ON rs.scope_id = sm.scope_id\n WHERE sm.device_id = ?\n AND sm.status = 'active'\n AND rs.status = 'active'\n AND sm.membership_epoch >= rs.membership_epoch").all(t), o =
|
|
4767
|
+
let a = e.prepare("SELECT sm.scope_id AS scope_id, rs.authority_type\n FROM scope_memberships sm\n JOIN replication_scopes rs ON rs.scope_id = sm.scope_id\n WHERE sm.device_id = ?\n AND sm.status = 'active'\n AND rs.status = 'active'\n AND sm.membership_epoch >= rs.membership_epoch").all(t), o = tc(a, n);
|
|
4728
4768
|
for (let n of a) if (n.scope_id != null) {
|
|
4729
4769
|
if ([
|
|
4730
4770
|
"local",
|
|
@@ -4734,7 +4774,7 @@ function qs(e, t, n = {}) {
|
|
|
4734
4774
|
r.add(n.scope_id);
|
|
4735
4775
|
continue;
|
|
4736
4776
|
}
|
|
4737
|
-
n.authority_type === "coordinator" && o?.trim() &&
|
|
4777
|
+
n.authority_type === "coordinator" && o?.trim() && As(e, {
|
|
4738
4778
|
deviceId: t,
|
|
4739
4779
|
scopeId: n.scope_id,
|
|
4740
4780
|
expectedPublicKey: o
|
|
@@ -4743,6 +4783,6 @@ function qs(e, t, n = {}) {
|
|
|
4743
4783
|
return [...r];
|
|
4744
4784
|
}
|
|
4745
4785
|
//#endregion
|
|
4746
|
-
export {
|
|
4786
|
+
export { Qa as $, We as $n, Yn as $t, Ho as A, Gt as An, vi as At, ro as B, Qt as Bn, Dr as Bt, No as C, Wt as Cn, Xi as Ct, ko as D, P as Dn, xa as Dt, Lo as E, on as En, ba as Et, ao as F, Ft as Fn, zr as Ft, Ha as G, en as Gn, ir as Gt, Ia as H, $t as Hn, xr as Ht, q as I, rt as In, kr as It, Sa as J, Ge as Jn, cr as Jt, Ca as K, ln as Kn, or as Kt, Ra as L, it as Ln, wr as Lt, Wo as M, Kt as Mn, Qr as Mt, oo as N, Xt as Nn, pi as Nt, Ao as O, O as On, V as Ot, Ea as P, qe as Pn, mi as Pt, Xa as Q, E as Qn, Xn as Qt, ja as R, j as Rn, Or as Rt, Y as S, Ut as Sn, Fi as St, Fo as T, an as Tn, U as Tt, Fa as U, tt as Un, Sr as Ut, io as V, Zt as Vn, Tr as Vt, Wa as W, cn as Wn, br as Wt, Va as X, Lt as Xn, dr as Xt, Ta as Y, Ke as Yn, ur as Yt, K as Z, Rt as Zn, tr as Zt, ss as _, et as _n, Ji as _t, $s as a, jn as an, Fe as ar, to as at, Go as b, nt as bn, ya as bt, ws as c, Cn as cn, Ba as ct, Cs as d, F as dn, Li as dt, er as en, Ve as er, Ya as et, vs as f, pn as fn, W as ft, us as g, gt as gn, Ni as gt, fs as h, k as hn, ua as ht, nc as i, Fn as in, ke as ir, eo as it, Uo as j, Yt as jn, yi as jt, Oo as k, Ye as kn, xi as kt, As as l, xn as ln, H as lt, Es as m, $e as mn, ki as mt, Rs as n, Vn as nn, Pe as nr, Ga as nt, Ls as o, An as on, Me as or, no as ot, ks as p, mn as pn, Oi as pt, J as q, tn as qn, rr as qt, ec as r, Wn as rn, Ee as rr, $a as rt, ms as s, Sn as sn, Te as sr, ka as st, zs as t, Un as tn, Be as tr, Ja as tt, Os as u, un, Si as ut, Yo as v, It as vn, Yi as vt, Io as w, sn as wn, Ci as wt, Ko as x, Ht as xn, Di as xt, Qo as y, D as yn, va as yt, za as z, Qe as zn, Er as zt };
|
|
4747
4787
|
|
|
4748
|
-
//# sourceMappingURL=scope-resolution-
|
|
4788
|
+
//# sourceMappingURL=scope-resolution-DXzf4k16.js.map
|