@codemem/core 0.33.0-alpha.2 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -15921,27 +15921,34 @@ function qy(e, t, n, r, i) {
15921
15921
  }
15922
15922
  //#endregion
15923
15923
  //#region src/project-scope-settings.ts
15924
- function Jy(e) {
15924
+ var Jy = "peer-received:";
15925
+ function Yy(e) {
15925
15926
  return e?.trim() || null;
15926
15927
  }
15927
- function Yy(e) {
15928
- let t = Jy(e);
15928
+ function Xy(e, t) {
15929
+ return `${e.inventory_source === "peer_received" ? "peer_received" : "local"}:${t.workspace_identity}`;
15930
+ }
15931
+ function Zy(e, t) {
15932
+ return !!e.prepare("SELECT 1 AS one\n FROM sessions s\n JOIN memory_items mi ON mi.session_id = s.id\n WHERE (s.cwd IS NULL OR substr(s.cwd, 1, length(?)) <> ?)\n AND COALESCE(TRIM(s.git_remote), TRIM(s.cwd), '') = ''\n AND mi.workspace_id IS NOT NULL\n AND TRIM(mi.workspace_id) = ?\n LIMIT 1").get(zy, zy, t);
15933
+ }
15934
+ function Qy(e) {
15935
+ let t = Yy(e);
15929
15936
  return t ? t.replaceAll("\\", "/").replace(/\/+$/, "") || t : null;
15930
15937
  }
15931
- function Xy(e, t) {
15938
+ function $y(e, t) {
15932
15939
  return e?.label || t;
15933
15940
  }
15934
- function Zy(e) {
15941
+ function eb(e) {
15935
15942
  return new Map(e.map((e) => [e.scope_id, e]));
15936
15943
  }
15937
- function Qy(e) {
15944
+ function tb(e) {
15938
15945
  return !e || e.scope_id === "local-default" ? !1 : e.authority_type === "local" ? e.kind === "team" || e.kind === "org" || e.kind === "client" : !0;
15939
15946
  }
15940
- function $y(e) {
15941
- let t = Jy(e)?.toLowerCase() ?? "";
15947
+ function nb(e) {
15948
+ let t = Yy(e)?.toLowerCase() ?? "";
15942
15949
  return new Set(t.match(/[a-z0-9][a-z0-9-]{1,}/g) ?? []);
15943
15950
  }
15944
- function eb(e) {
15951
+ function rb(e) {
15945
15952
  let t = new Set([
15946
15953
  "domain",
15947
15954
  "sharing",
@@ -15956,13 +15963,13 @@ function eb(e) {
15956
15963
  "oss",
15957
15964
  "personal",
15958
15965
  "work"
15959
- ]), r = [...$y(`${e.scope_id} ${e.label}`)].filter((e) => !t.has(e));
15966
+ ]), r = [...nb(`${e.scope_id} ${e.label}`)].filter((e) => !t.has(e));
15960
15967
  return {
15961
15968
  generic: r.filter((e) => n.has(e)),
15962
15969
  specific: r.filter((e) => !n.has(e))
15963
15970
  };
15964
15971
  }
15965
- function tb(e) {
15972
+ function ib(e) {
15966
15973
  let t = [];
15967
15974
  return e.git_remote && t.push({
15968
15975
  signal: "git_remote",
@@ -15975,11 +15982,11 @@ function tb(e) {
15975
15982
  text: e.workspace_identity
15976
15983
  }), t;
15977
15984
  }
15978
- function nb(e, t) {
15985
+ function ab(e, t) {
15979
15986
  if (e.resolution_reason !== "local_default" || e.workspace_identity.startsWith("unmapped:")) return null;
15980
- for (let n of tb(e)) {
15981
- let e = $y(n.text), [r, i] = t.filter((e) => e.scope_id !== "local-default" && e.scope_id !== "legacy-shared-review" && e.status === "active").flatMap((t) => {
15982
- let n = eb(t), r = n.specific.filter((t) => e.has(t)), i = n.generic.filter((n) => n === "personal" && e.has(n) && t.kind === n);
15987
+ for (let n of ib(e)) {
15988
+ let e = nb(n.text), [r, i] = t.filter((e) => e.scope_id !== "local-default" && e.scope_id !== "legacy-shared-review" && e.status === "active").flatMap((t) => {
15989
+ let n = rb(t), r = n.specific.filter((t) => e.has(t)), i = n.generic.filter((n) => n === "personal" && e.has(n) && t.kind === n);
15983
15990
  return r.length === 0 && i.length === 0 ? [] : [{
15984
15991
  scope: t,
15985
15992
  matches: [...r, ...i],
@@ -15987,7 +15994,7 @@ function nb(e, t) {
15987
15994
  }];
15988
15995
  }).toSorted((e, t) => t.score - e.score);
15989
15996
  if (!r || i && i.score === r.score) continue;
15990
- let a = Xy(r.scope, r.scope.scope_id), o = n.signal === "git_remote" ? "git remote" : n.signal;
15997
+ let a = $y(r.scope, r.scope.scope_id), o = n.signal === "git_remote" ? "git remote" : n.signal;
15991
15998
  return {
15992
15999
  scopeId: r.scope.scope_id,
15993
16000
  reason: `${a} is suggested because the ${o} contains ${r.matches.join(", ")}. Confirm before mapping; this does not grant peer access.`,
@@ -15996,18 +16003,18 @@ function nb(e, t) {
15996
16003
  }
15997
16004
  return null;
15998
16005
  }
15999
- function rb(e) {
16006
+ function ob(e) {
16000
16007
  return /[*?]/.test(e);
16001
16008
  }
16002
- function ib(e) {
16009
+ function sb(e) {
16003
16010
  let t = e.search(/[*?]/);
16004
16011
  return (t >= 0 ? e.slice(0, t) : e).replace(/\/+$/, "");
16005
16012
  }
16006
- function ab(e) {
16007
- let t = ib(e.replaceAll("\\", "/"));
16013
+ function cb(e) {
16014
+ let t = sb(e.replaceAll("\\", "/"));
16008
16015
  return t === "~" || /^\/Users\/[^/]+$/i.test(t) || /^\/home\/[^/]+$/i.test(t) || /^\/var\/home\/[^/]+$/i.test(t) || /^[A-Z]:\/Users\/[^/]+$/i.test(t);
16009
16016
  }
16010
- function ob(e) {
16017
+ function lb(e) {
16011
16018
  let t = JSON.stringify({
16012
16019
  code: e.code,
16013
16020
  mapping_id: e.mapping_id ?? null,
@@ -16019,18 +16026,18 @@ function ob(e) {
16019
16026
  });
16020
16027
  return `psg_${u("sha256").update(t).digest("hex").slice(0, 32)}`;
16021
16028
  }
16022
- function sb(e) {
16029
+ function ub(e) {
16023
16030
  return e.requires_confirmation ? {
16024
16031
  ...e,
16025
- confirmation_token: ob(e)
16032
+ confirmation_token: lb(e)
16026
16033
  } : e;
16027
16034
  }
16028
- function cb(e, t) {
16035
+ function db(e, t) {
16029
16036
  if (e.workspace_identity) return [];
16030
- let n = Yy(e.project_pattern) ?? e.project_pattern, r = t.get(e.scope_id);
16031
- if (!Qy(r)) return [];
16032
- let i = Xy(r, e.scope_id), a = [];
16033
- return rb(n) && a.push({
16037
+ let n = Qy(e.project_pattern) ?? e.project_pattern, r = t.get(e.scope_id);
16038
+ if (!tb(r)) return [];
16039
+ let i = $y(r, e.scope_id), a = [];
16040
+ return ob(n) && a.push({
16034
16041
  code: "broad_org_domain_pattern",
16035
16042
  severity: "warning",
16036
16043
  message: `Wildcard project pattern ${n} can catch multiple projects. Review before attaching it to ${i}.`,
@@ -16038,7 +16045,7 @@ function cb(e, t) {
16038
16045
  scope_id: e.scope_id,
16039
16046
  mapping_id: e.id ?? null,
16040
16047
  project_pattern: e.project_pattern
16041
- }), ab(n) && a.push({
16048
+ }), cb(n) && a.push({
16042
16049
  code: "home_directory_org_domain_pattern",
16043
16050
  severity: "warning",
16044
16051
  message: `Home-directory project pattern ${n} can mix personal and work projects. Review before attaching it to ${i}.`,
@@ -16046,21 +16053,22 @@ function cb(e, t) {
16046
16053
  scope_id: e.scope_id,
16047
16054
  mapping_id: e.id ?? null,
16048
16055
  project_pattern: e.project_pattern
16049
- }), a.map(sb);
16056
+ }), a.map(ub);
16050
16057
  }
16051
- function lb(e) {
16052
- return (Jy(e.project) ?? Jy(e.display_project) ?? e.workspace_identity).toLowerCase();
16058
+ function fb(e) {
16059
+ return (Yy(e.project) ?? Yy(e.display_project) ?? e.workspace_identity).toLowerCase();
16053
16060
  }
16054
- function ub(e) {
16061
+ function pb(e) {
16055
16062
  let t = /* @__PURE__ */ new Map();
16056
16063
  for (let n of e) {
16057
- let e = lb(n);
16064
+ let e = fb(n);
16058
16065
  t.set(e, [...t.get(e) ?? [], n]);
16059
16066
  }
16060
16067
  return t;
16061
16068
  }
16062
- function db(e, t) {
16069
+ function mb(e, t) {
16063
16070
  let n = [];
16071
+ if (e.read_only) return n;
16064
16072
  e.resolution_reason === "local_default" && n.push({
16065
16073
  code: "unknown_project_local_only",
16066
16074
  severity: "info",
@@ -16069,7 +16077,7 @@ function db(e, t) {
16069
16077
  workspace_identity: e.workspace_identity,
16070
16078
  scope_id: Ei
16071
16079
  });
16072
- let r = (t.get(lb(e)) ?? []).filter((t) => t.workspace_identity !== e.workspace_identity);
16080
+ let r = (t.get(fb(e)) ?? []).filter((t) => t.workspace_identity !== e.workspace_identity);
16073
16081
  return r.length > 0 && n.push({
16074
16082
  code: "basename_collision_review",
16075
16083
  severity: "info",
@@ -16078,21 +16086,21 @@ function db(e, t) {
16078
16086
  workspace_identity: e.workspace_identity,
16079
16087
  related_workspace_identities: r.map((e) => e.workspace_identity),
16080
16088
  related_projects: r.map((e) => e.display_project)
16081
- }), n.map(sb);
16089
+ }), n.map(ub);
16082
16090
  }
16083
- function fb(e) {
16084
- let t = ub(e);
16091
+ function hb(e) {
16092
+ let t = pb(e);
16085
16093
  return e.map((e) => ({
16086
16094
  ...e,
16087
- guardrail_warnings: db(e, t)
16095
+ guardrail_warnings: mb(e, t)
16088
16096
  }));
16089
16097
  }
16090
- function pb(e) {
16098
+ function gb(e) {
16091
16099
  let t = /* @__PURE__ */ new Set();
16092
- return e.resolved_scope_id === "local-default" && t.add("local_only"), e.resolved_scope_id === "legacy-shared-review" && t.add("legacy_review"), e.identity_source === "unmapped" && t.add("unmapped"), e.suggested_scope_id && e.suggested_scope_id !== e.resolved_scope_id && t.add("suggested"), e.mapping_id != null && t.add("explicitly_mapped"), (e.guardrail_warnings ?? []).some((e) => e.severity === "warning") && t.add("needs_attention"), [...t].sort();
16100
+ return e.read_only ? ["received"] : (!e.read_only && e.resolved_scope_id === "local-default" && t.add("local_only"), e.resolved_scope_id === "legacy-shared-review" && t.add("legacy_review"), e.identity_source === "unmapped" && t.add("unmapped"), e.suggested_scope_id && e.suggested_scope_id !== e.resolved_scope_id && t.add("suggested"), e.mapping_id != null && t.add("explicitly_mapped"), (e.guardrail_warnings ?? []).some((e) => e.severity === "warning") && t.add("needs_attention"), [...t].sort());
16093
16101
  }
16094
- function mb(e, t) {
16095
- let n = Jy(t)?.toLowerCase();
16102
+ function _b(e, t) {
16103
+ let n = Yy(t)?.toLowerCase();
16096
16104
  return n ? [
16097
16105
  e.display_project,
16098
16106
  e.project,
@@ -16104,7 +16112,7 @@ function mb(e, t) {
16104
16112
  e.suggested_scope_id
16105
16113
  ].filter((e) => typeof e == "string" && e.length > 0).some((e) => e.toLowerCase().includes(n)) : !0;
16106
16114
  }
16107
- function hb(e, t, n) {
16115
+ function vb(e, t, n) {
16108
16116
  let r = Mi({
16109
16117
  gitRemote: e.git_remote,
16110
16118
  gitBranch: e.git_branch,
@@ -16121,21 +16129,23 @@ function hb(e, t, n) {
16121
16129
  }), a = {
16122
16130
  workspace_identity: r.value,
16123
16131
  identity_source: r.source,
16124
- display_project: r.displayProject ?? Jy(e.project) ?? Jy(e.cwd) ?? r.value,
16125
- project: Jy(e.project),
16126
- cwd: Jy(e.cwd),
16127
- git_remote: Jy(e.git_remote),
16128
- git_branch: Jy(e.git_branch),
16132
+ display_project: r.displayProject ?? Yy(e.project) ?? Yy(e.cwd) ?? r.value,
16133
+ project: Yy(e.project),
16134
+ cwd: Yy(e.cwd),
16135
+ git_remote: Yy(e.git_remote),
16136
+ git_branch: Yy(e.git_branch),
16129
16137
  latest_session_at: e.started_at,
16130
16138
  resolved_scope_id: i.scopeId,
16131
16139
  resolution_reason: i.reason,
16132
16140
  mapping_id: i.mapping?.id ?? null,
16133
16141
  matched_pattern: i.matchedPattern,
16142
+ read_only: !1,
16143
+ read_only_reason: null,
16134
16144
  suggested_scope_id: null,
16135
16145
  suggestion_reason: null,
16136
16146
  suggestion_signal: null,
16137
16147
  guardrail_warnings: []
16138
- }, o = nb(a, n);
16148
+ }, o = ab(a, n);
16139
16149
  return {
16140
16150
  ...a,
16141
16151
  suggested_scope_id: o?.scopeId ?? null,
@@ -16143,7 +16153,7 @@ function hb(e, t, n) {
16143
16153
  suggestion_signal: o?.signal ?? null
16144
16154
  };
16145
16155
  }
16146
- function gb(e) {
16156
+ function yb(e) {
16147
16157
  let t = /* @__PURE__ */ new Set();
16148
16158
  return e.filter((e) => {
16149
16159
  let n = [
@@ -16154,28 +16164,28 @@ function gb(e) {
16154
16164
  e.related_workspace_identities?.join("|") ?? ""
16155
16165
  ].join("\0");
16156
16166
  return t.has(n) ? !1 : (t.add(n), !0);
16157
- }).map(sb);
16167
+ }).map(ub);
16158
16168
  }
16159
- function _b(e, t) {
16169
+ function bb(e, t) {
16160
16170
  if (!e && !/[\\/:]/.test(t) && !(/[*?]/.test(t) && /[\\/:]/.test(t.replace(/[*?]/g, "")))) throw Error("project_pattern must use a canonical path, remote, or workspace pattern");
16161
16171
  }
16162
- function vb(e) {
16172
+ function xb(e) {
16163
16173
  return {
16164
16174
  scope_id: String(e.scope_id ?? ""),
16165
16175
  label: String(e.label ?? ""),
16166
16176
  kind: String(e.kind ?? "user"),
16167
16177
  authority_type: String(e.authority_type ?? "local"),
16168
- coordinator_id: Jy(e.coordinator_id),
16169
- group_id: Jy(e.group_id),
16178
+ coordinator_id: Yy(e.coordinator_id),
16179
+ group_id: Yy(e.group_id),
16170
16180
  membership_epoch: Number(e.membership_epoch ?? 0),
16171
16181
  status: String(e.status ?? "active"),
16172
16182
  updated_at: String(e.updated_at ?? "")
16173
16183
  };
16174
16184
  }
16175
- function yb(e) {
16185
+ function Sb(e) {
16176
16186
  return {
16177
16187
  id: Number(e.id ?? 0),
16178
- workspace_identity: Yy(e.workspace_identity),
16188
+ workspace_identity: Qy(e.workspace_identity),
16179
16189
  project_pattern: String(e.project_pattern ?? ""),
16180
16190
  scope_id: String(e.scope_id ?? ""),
16181
16191
  priority: Number(e.priority ?? 0),
@@ -16185,55 +16195,55 @@ function yb(e) {
16185
16195
  guardrail_warnings: []
16186
16196
  };
16187
16197
  }
16188
- function bb(e) {
16189
- return Xv(e), e.prepare("SELECT scope_id, label, kind, authority_type, coordinator_id, group_id,\n membership_epoch, status, updated_at\n FROM replication_scopes\n WHERE status = 'active'\n ORDER BY CASE WHEN scope_id = ? THEN 0 ELSE 1 END, label COLLATE NOCASE, scope_id").all(Ei).map((e) => vb(e));
16198
+ function Cb(e) {
16199
+ return Xv(e), e.prepare("SELECT scope_id, label, kind, authority_type, coordinator_id, group_id,\n membership_epoch, status, updated_at\n FROM replication_scopes\n WHERE status = 'active'\n ORDER BY CASE WHEN scope_id = ? THEN 0 ELSE 1 END, label COLLATE NOCASE, scope_id").all(Ei).map((e) => xb(e));
16190
16200
  }
16191
- function xb(e) {
16201
+ function wb(e) {
16192
16202
  Xv(e);
16193
- let t = Zy(bb(e));
16203
+ let t = eb(Cb(e));
16194
16204
  return e.prepare("SELECT id, workspace_identity, project_pattern, scope_id, priority, source, created_at, updated_at\n FROM project_scope_mappings\n ORDER BY priority DESC, updated_at DESC, id DESC").all().map((e) => {
16195
- let n = yb(e);
16205
+ let n = Sb(e);
16196
16206
  return {
16197
16207
  ...n,
16198
- guardrail_warnings: cb(n, t)
16208
+ guardrail_warnings: db(n, t)
16199
16209
  };
16200
16210
  });
16201
16211
  }
16202
- function Sb(e, t) {
16212
+ function Tb(e, t) {
16203
16213
  let n = e.prepare("SELECT id, workspace_identity, project_pattern, scope_id, priority, source, created_at, updated_at\n FROM project_scope_mappings\n WHERE id = ?\n LIMIT 1").get(t);
16204
- return n ? yb(n) : null;
16214
+ return n ? Sb(n) : null;
16205
16215
  }
16206
- function Cb(e, t) {
16216
+ function Eb(e, t) {
16207
16217
  let n = e.prepare("SELECT id, workspace_identity, project_pattern, scope_id, priority, source, created_at, updated_at\n FROM project_scope_mappings\n WHERE workspace_identity = ?\n ORDER BY priority DESC, updated_at DESC, id DESC\n LIMIT 1").get(t);
16208
- return n ? yb(n) : null;
16218
+ return n ? Sb(n) : null;
16209
16219
  }
16210
- function wb(e, t) {
16220
+ function Db(e, t) {
16211
16221
  if (t === "legacy-shared-review") throw Error("legacy-shared-review is a review bucket, not an assignable Sharing domain");
16212
16222
  if (!e.prepare("SELECT 1 FROM replication_scopes WHERE scope_id = ? AND status = 'active' LIMIT 1").get(t)) throw Error(`scope_id ${t} is not an active Sharing domain`);
16213
16223
  }
16214
- function Tb(e, t) {
16215
- let n = t.id == null ? null : Number(t.id), r = n && Number.isInteger(n) ? Sb(e, n) : null, i = Yy(t.workspace_identity) ?? r?.workspace_identity ?? null, a = i ? Cb(e, i) : null, o = r ?? a, s = Jy(t.project_pattern) ?? o?.project_pattern ?? i, c = t.priority == null ? o?.priority ?? 0 : Number(t.priority);
16224
+ function Ob(e, t) {
16225
+ let n = t.id == null ? null : Number(t.id), r = n && Number.isInteger(n) ? Tb(e, n) : null, i = Qy(t.workspace_identity) ?? r?.workspace_identity ?? null, a = i ? Eb(e, i) : null, o = r ?? a, s = Yy(t.project_pattern) ?? o?.project_pattern ?? i, c = t.priority == null ? o?.priority ?? 0 : Number(t.priority);
16216
16226
  return {
16217
16227
  existing: o,
16218
16228
  workspaceIdentity: i,
16219
16229
  projectPattern: s,
16220
- scopeId: Jy(t.scope_id) ?? "",
16230
+ scopeId: Yy(t.scope_id) ?? "",
16221
16231
  priority: c,
16222
- source: Jy(t.source) ?? "user"
16232
+ source: Yy(t.source) ?? "user"
16223
16233
  };
16224
16234
  }
16225
- function Eb(e, t) {
16235
+ function kb(e, t) {
16226
16236
  Xv(e);
16227
- let n = Tb(e, t), r = Zy(bb(e)), i = [];
16228
- n.projectPattern && n.scopeId && i.push(...cb({
16237
+ let n = Ob(e, t), r = eb(Cb(e)), i = [];
16238
+ n.projectPattern && n.scopeId && i.push(...db({
16229
16239
  id: n.existing?.id ?? 0,
16230
16240
  workspace_identity: n.workspaceIdentity,
16231
16241
  project_pattern: n.projectPattern,
16232
16242
  scope_id: n.scopeId
16233
16243
  }, r));
16234
- let a = n.workspaceIdentity ? Db(e, { limit: null }).find((e) => e.workspace_identity === n.workspaceIdentity) : null, o = r.get(n.scopeId);
16235
- if (a && i.push(...a.guardrail_warnings.filter((e) => e.code !== "basename_collision_review" || Qy(o))), n.scopeId && n.existing && n.existing.scope_id !== n.scopeId) {
16236
- let e = Xy(r.get(n.existing.scope_id), n.existing.scope_id), t = Xy(r.get(n.scopeId), n.scopeId);
16244
+ let a = n.workspaceIdentity ? Ab(e, { limit: null }).find((e) => e.workspace_identity === n.workspaceIdentity) : null, o = r.get(n.scopeId);
16245
+ if (a && i.push(...a.guardrail_warnings.filter((e) => e.code !== "basename_collision_review" || tb(o))), n.scopeId && n.existing && n.existing.scope_id !== n.scopeId) {
16246
+ let e = $y(r.get(n.existing.scope_id), n.existing.scope_id), t = $y(r.get(n.scopeId), n.scopeId);
16237
16247
  i.push({
16238
16248
  code: "scope_reassignment_old_copies",
16239
16249
  severity: "warning",
@@ -16251,12 +16261,12 @@ function Eb(e, t) {
16251
16261
  requested_scope_id: n.scopeId,
16252
16262
  requested_workspace_identity: n.workspaceIdentity,
16253
16263
  requested_project_pattern: n.projectPattern,
16254
- warnings: gb(i)
16264
+ warnings: yb(i)
16255
16265
  };
16256
16266
  }
16257
- function Db(e, t = {}) {
16267
+ function Ab(e, t = {}) {
16258
16268
  Xv(e);
16259
- let n = t.limit === null ? null : Math.max(1, Math.min(t.limit ?? 250, 1e3)), r = xb(e), i = bb(e), a = `SELECT
16269
+ let n = t.limit === null ? null : Math.max(1, Math.min(t.limit ?? 250, 1e3)), r = wb(e), i = Cb(e), a = `SELECT
16260
16270
  s.id,
16261
16271
  s.started_at,
16262
16272
  s.cwd,
@@ -16284,29 +16294,42 @@ function Db(e, t = {}) {
16284
16294
  project: e.project,
16285
16295
  workspaceId: e.workspace_id
16286
16296
  });
16287
- s.has(t.value) || (s.add(t.value), c.push(hb(e, r, i)));
16297
+ s.has(t.value) || (s.add(t.value), c.push(vb(e, r, i)));
16288
16298
  }
16289
- return fb(c.toSorted((e, t) => e.display_project.localeCompare(t.display_project) || e.workspace_identity.localeCompare(t.workspace_identity)));
16299
+ return hb(c.toSorted((e, t) => e.display_project.localeCompare(t.display_project) || e.workspace_identity.localeCompare(t.workspace_identity)));
16290
16300
  }
16291
- function Ob(e, t = {}) {
16301
+ function jb(e, t = {}) {
16292
16302
  Xv(e);
16293
- let n = Math.max(1, Math.min(t.limit ?? 50, 250)), r = Math.max(0, t.offset ?? 0), i = xb(e), a = bb(e), o = e.prepare("SELECT\n s.id,\n MAX(s.started_at) AS started_at,\n s.cwd,\n s.project,\n s.git_remote,\n s.git_branch,\n (\n SELECT mi.workspace_id\n FROM memory_items mi\n WHERE mi.session_id = s.id\n AND mi.workspace_id IS NOT NULL\n AND TRIM(mi.workspace_id) <> ''\n ORDER BY mi.id DESC\n LIMIT 1\n ) AS workspace_id,\n COUNT(DISTINCT s.id) AS session_count,\n COUNT(mi_count.id) AS memory_count\n FROM sessions s\n LEFT JOIN memory_items mi_count ON mi_count.session_id = s.id\n WHERE (\n COALESCE(TRIM(s.git_remote), TRIM(s.cwd), TRIM(s.project), '') <> ''\n OR mi_count.id IS NOT NULL\n )\n AND (s.cwd IS NULL OR substr(s.cwd, 1, length(?)) <> ?)\n GROUP BY s.id\n ORDER BY MAX(s.started_at) DESC, s.id DESC").all(zy, zy), s = /* @__PURE__ */ new Map(), c = [];
16294
- for (let e of o) {
16295
- let t = hb(e, i, a), n = s.get(t.workspace_identity);
16296
- if (n) {
16297
- n.memory_count = (n.memory_count ?? 0) + Number(e.memory_count ?? 0), n.session_count += Number(e.session_count ?? 1);
16303
+ let n = Math.max(1, Math.min(t.limit ?? 50, 250)), r = Math.max(0, t.offset ?? 0), i = wb(e), a = Cb(e), o = e.prepare("SELECT\n s.id,\n 'local' AS inventory_source,\n MAX(s.started_at) AS started_at,\n s.cwd,\n s.project,\n s.git_remote,\n s.git_branch,\n (\n SELECT mi.workspace_id\n FROM memory_items mi\n WHERE mi.session_id = s.id\n AND mi.workspace_id IS NOT NULL\n AND TRIM(mi.workspace_id) <> ''\n ORDER BY mi.id DESC\n LIMIT 1\n ) AS workspace_id,\n COUNT(DISTINCT s.id) AS session_count,\n COUNT(mi_count.id) AS memory_count\n FROM sessions s\n LEFT JOIN memory_items mi_count ON mi_count.session_id = s.id\n WHERE (\n COALESCE(TRIM(s.git_remote), TRIM(s.cwd), TRIM(s.project), '') <> ''\n OR mi_count.id IS NOT NULL\n )\n AND (s.cwd IS NULL OR substr(s.cwd, 1, length(?)) <> ?)\n GROUP BY s.id\n ORDER BY MAX(s.started_at) DESC, s.id DESC").all(zy, zy), s = e.prepare("SELECT\n MIN(s.id) AS id,\n 'peer_received' AS inventory_source,\n MAX(COALESCE(mi.updated_at, s.started_at)) AS started_at,\n NULL AS cwd,\n TRIM(mi.project) AS project,\n NULL AS git_remote,\n NULL AS git_branch,\n 'peer-received:' || COALESCE(NULLIF(TRIM(mi.origin_device_id), ''), 'unknown') || ':project:' || TRIM(mi.project) AS workspace_id,\n 0 AS session_count,\n COUNT(mi.id) AS memory_count\n FROM memory_items mi\n JOIN sessions s ON s.id = mi.session_id\n WHERE mi.active = 1\n AND mi.project IS NOT NULL\n AND TRIM(mi.project) <> ''\n AND s.cwd IS NOT NULL\n AND substr(s.cwd, 1, length(?)) = ?\n GROUP BY TRIM(mi.project), workspace_id\n ORDER BY MAX(COALESCE(mi.updated_at, s.started_at)) DESC, TRIM(mi.project) ASC").all(zy, zy), c = /* @__PURE__ */ new Map(), l = [];
16304
+ for (let e of [...o, ...s]) {
16305
+ let t = e.inventory_source === "peer_received", n = {
16306
+ ...vb(e, i, a),
16307
+ read_only: t,
16308
+ read_only_reason: t ? "peer_received" : null,
16309
+ ...t ? {
16310
+ mapping_id: null,
16311
+ matched_pattern: null,
16312
+ resolution_reason: "local_default",
16313
+ resolved_scope_id: Ei,
16314
+ suggested_scope_id: null,
16315
+ suggestion_reason: null,
16316
+ suggestion_signal: null
16317
+ } : {}
16318
+ }, r = Xy(e, n), o = c.get(r);
16319
+ if (o) {
16320
+ o.memory_count = (o.memory_count ?? 0) + Number(e.memory_count ?? 0), o.session_count += Number(e.session_count ?? 1), t || (o.read_only = !1, o.read_only_reason = null);
16298
16321
  continue;
16299
16322
  }
16300
- let r = {
16301
- ...t,
16323
+ let s = {
16324
+ ...n,
16302
16325
  memory_count: Number(e.memory_count ?? 0),
16303
16326
  session_count: Number(e.session_count ?? 1),
16304
16327
  statuses: []
16305
16328
  };
16306
- s.set(t.workspace_identity, r), c.push(r);
16329
+ c.set(r, s), l.push(s);
16307
16330
  }
16308
16331
  for (let e of i) {
16309
- if (!e.workspace_identity || s.has(e.workspace_identity)) continue;
16332
+ if (!e.workspace_identity || c.has(`local:${e.workspace_identity}`)) continue;
16310
16333
  let t = {
16311
16334
  workspace_identity: e.workspace_identity,
16312
16335
  identity_source: "workspace_id",
@@ -16320,6 +16343,8 @@ function Ob(e, t = {}) {
16320
16343
  resolution_reason: "exact_mapping",
16321
16344
  mapping_id: e.id,
16322
16345
  matched_pattern: null,
16346
+ read_only: !1,
16347
+ read_only_reason: null,
16323
16348
  suggested_scope_id: null,
16324
16349
  suggestion_reason: null,
16325
16350
  suggestion_signal: null,
@@ -16328,93 +16353,116 @@ function Ob(e, t = {}) {
16328
16353
  session_count: 0,
16329
16354
  statuses: []
16330
16355
  };
16331
- s.set(e.workspace_identity, t), c.push(t);
16356
+ c.set(`local:${e.workspace_identity}`, t), l.push(t);
16332
16357
  }
16333
- let l = fb(c).map((e) => {
16334
- let t = c.find((t) => t.workspace_identity === e.workspace_identity);
16358
+ let u = hb(l).map((e, t) => {
16359
+ let n = l[t];
16335
16360
  return {
16336
16361
  ...e,
16337
- memory_count: t?.memory_count ?? null,
16338
- session_count: t?.session_count ?? 0,
16339
- statuses: pb(e)
16362
+ memory_count: n?.memory_count ?? null,
16363
+ session_count: n?.session_count ?? 0,
16364
+ statuses: gb(e)
16340
16365
  };
16341
- }).filter((e) => mb(e, t.query)).filter((e) => !t.scopeId || e.resolved_scope_id === t.scopeId).filter((e) => !t.identitySource || e.identity_source === t.identitySource).filter((e) => !t.status || e.statuses.some((e) => e === t.status)).toSorted((e, t) => (e.latest_session_at == null ? 1 : t.latest_session_at == null ? -1 : 0) || String(t.latest_session_at ?? "").localeCompare(String(e.latest_session_at ?? "")) || e.display_project.localeCompare(t.display_project) || e.workspace_identity.localeCompare(t.workspace_identity));
16366
+ }).filter((e) => _b(e, t.query)).filter((e) => !t.scopeId || e.resolved_scope_id === t.scopeId).filter((e) => !t.identitySource || e.identity_source === t.identitySource).filter((e) => !t.status || e.statuses.some((e) => e === t.status)).toSorted((e, t) => (e.latest_session_at == null ? 1 : t.latest_session_at == null ? -1 : 0) || String(t.latest_session_at ?? "").localeCompare(String(e.latest_session_at ?? "")) || e.display_project.localeCompare(t.display_project) || e.workspace_identity.localeCompare(t.workspace_identity));
16342
16367
  return {
16343
- projects: l.slice(r, r + n),
16344
- total: l.length,
16368
+ projects: u.slice(r, r + n),
16369
+ total: u.length,
16345
16370
  limit: n,
16346
16371
  offset: r,
16347
- has_more: r + n < l.length
16372
+ has_more: r + n < u.length
16348
16373
  };
16349
16374
  }
16350
- function kb(e, t) {
16375
+ function Mb(e, t) {
16351
16376
  Xv(e);
16352
- let n = Yy(t.workspaceIdentity);
16353
- if (!n) throw Error("workspace_identity must be a non-empty string");
16354
- if (n.startsWith("unmapped:")) throw Error("unmapped projects cannot be reassigned until they have a stable identity");
16355
- let r = Jy(t.project);
16356
- if (!r) throw Error("project must be a non-empty string");
16357
- let i = e.prepare("SELECT\n s.id,\n s.started_at,\n s.cwd,\n s.project,\n s.git_remote,\n s.git_branch,\n (\n SELECT mi.workspace_id\n FROM memory_items mi\n WHERE mi.session_id = s.id\n AND mi.workspace_id IS NOT NULL\n AND TRIM(mi.workspace_id) <> ''\n ORDER BY mi.id DESC\n LIMIT 1\n ) AS workspace_id,\n COUNT(mi_count.id) AS memory_count\n FROM sessions s\n LEFT JOIN memory_items mi_count ON mi_count.session_id = s.id\n WHERE COALESCE(TRIM(s.git_remote), TRIM(s.cwd), TRIM(s.project), '') <> ''\n OR mi_count.id IS NOT NULL\n GROUP BY s.id").all().filter((e) => Mi({
16377
+ let n = Yy(t.deviceId);
16378
+ if (!n) throw Error("device_id must be a non-empty string");
16379
+ let r = Qy(t.workspaceIdentity);
16380
+ if (!r) throw Error("workspace_identity must be a non-empty string");
16381
+ if (r.startsWith("unmapped:")) throw Error("unmapped projects cannot be reassigned until they have a stable identity");
16382
+ let i = Yy(t.project);
16383
+ if (!i) throw Error("project must be a non-empty string");
16384
+ let a = e.prepare("SELECT\n s.id,\n s.started_at,\n s.cwd,\n s.project,\n s.git_remote,\n s.git_branch,\n (\n SELECT mi.workspace_id\n FROM memory_items mi\n WHERE mi.session_id = s.id\n AND mi.workspace_id IS NOT NULL\n AND TRIM(mi.workspace_id) <> ''\n ORDER BY mi.id DESC\n LIMIT 1\n ) AS workspace_id,\n COUNT(mi_count.id) AS memory_count\n FROM sessions s\n LEFT JOIN memory_items mi_count ON mi_count.session_id = s.id\n WHERE COALESCE(TRIM(s.git_remote), TRIM(s.cwd), TRIM(s.project), '') <> ''\n OR mi_count.id IS NOT NULL\n GROUP BY s.id").all().filter((e) => Mi({
16358
16385
  gitRemote: e.git_remote,
16359
16386
  gitBranch: e.git_branch,
16360
16387
  cwd: e.cwd,
16361
16388
  project: e.project,
16362
16389
  workspaceId: e.workspace_id
16363
- }).value === n);
16364
- if (i.length === 0) throw Error("project identity not found");
16365
- let a = [...new Set(i.map((e) => Jy(e.project) ?? "").filter(Boolean))].sort(), o = i.reduce((e, t) => e + Number(t.memory_count ?? 0), 0), s = e.prepare("UPDATE sessions SET project = ? WHERE id = ?");
16390
+ }).value === r);
16391
+ if (a.length === 0) throw Error("project identity not found");
16392
+ let o = (/* @__PURE__ */ new Date()).toISOString(), s = a.map((e) => e.id), c = s.map(() => "?").join(", "), l = e.prepare(`SELECT id, session_id, project
16393
+ FROM memory_items
16394
+ WHERE session_id IN (${c})
16395
+ AND active = 1
16396
+ AND (origin_device_id IS NULL OR TRIM(origin_device_id) = '' OR origin_device_id = ?)`).all(...s, n), u = new Set(l.map((e) => e.session_id)), d = a.filter((e) => u.has(e.id) || Number(e.memory_count ?? 0) === 0);
16397
+ if (d.length === 0) throw Error("project identity has no source-owned memories on this device");
16398
+ let f = [...new Set(d.map((e) => Yy(e.project) ?? "").filter(Boolean))].sort(), p = l.filter((e) => (Yy(e.project) ?? "") !== i), m = p.length, h = e.prepare("UPDATE sessions SET project = ? WHERE id = ?");
16366
16399
  return e.transaction(() => {
16367
- for (let e of i) s.run(r, e.id);
16400
+ for (let e of d) h.run(i, e.id);
16401
+ if (p.length > 0) {
16402
+ let t = p.map((e) => Number(e.id));
16403
+ e.prepare(`UPDATE memory_items
16404
+ SET project = ?, updated_at = ?, rev = COALESCE(rev, 0) + 1
16405
+ WHERE id IN (${t.map(() => "?").join(", ")})`).run(i, o, ...t);
16406
+ for (let r of t) hd(e, {
16407
+ memoryId: r,
16408
+ opType: "upsert",
16409
+ deviceId: n,
16410
+ clockDeviceId: n,
16411
+ clockUpdatedAt: o,
16412
+ createdAt: o
16413
+ });
16414
+ }
16368
16415
  })(), {
16369
- moved_memory_count: o,
16370
- moved_session_count: i.length,
16371
- previous_projects: a,
16372
- project: r,
16373
- workspace_identity: n
16416
+ moved_memory_count: m,
16417
+ moved_session_count: d.length,
16418
+ previous_projects: f,
16419
+ project: i,
16420
+ workspace_identity: r
16374
16421
  };
16375
16422
  }
16376
- function Ab(e, t) {
16423
+ function Nb(e, t) {
16377
16424
  Xv(e);
16378
- let n = Tb(e, t), r = n.scopeId;
16425
+ let n = Ob(e, t), r = n.scopeId;
16379
16426
  if (!r) throw Error("scope_id must be a non-empty string");
16380
- wb(e, r);
16427
+ Db(e, r);
16381
16428
  let { existing: i, workspaceIdentity: a } = n;
16382
16429
  if (a?.startsWith("unmapped:")) throw Error("unmapped projects cannot be assigned to a Sharing domain");
16430
+ if (a?.startsWith(Jy) && !Zy(e, a)) throw Error("peer-received projects cannot be assigned on this device");
16383
16431
  let o = n.projectPattern;
16384
16432
  if (!o) throw Error("project_pattern or workspace_identity is required");
16385
- _b(a, o);
16433
+ bb(a, o);
16386
16434
  let s = n.priority;
16387
16435
  if (!Number.isFinite(s) || !Number.isInteger(s)) throw Error("priority must be an integer");
16388
16436
  let c = n.source, l = (/* @__PURE__ */ new Date()).toISOString();
16389
16437
  if (i) {
16390
16438
  e.prepare("UPDATE project_scope_mappings\n SET workspace_identity = ?, project_pattern = ?, scope_id = ?, priority = ?, source = ?, updated_at = ?\n WHERE id = ?").run(a, o, r, s, c, l, i.id);
16391
- let t = Sb(e, i.id);
16439
+ let t = Tb(e, i.id);
16392
16440
  if (!t) throw Error("project_scope_mapping update returned no row");
16393
16441
  return t;
16394
16442
  }
16395
- let u = e.prepare("INSERT INTO project_scope_mappings(\n workspace_identity, project_pattern, scope_id, priority, source, created_at, updated_at\n ) VALUES (?, ?, ?, ?, ?, ?, ?)").run(a, o, r, s, c, l, l), d = Sb(e, Number(u.lastInsertRowid));
16443
+ let u = e.prepare("INSERT INTO project_scope_mappings(\n workspace_identity, project_pattern, scope_id, priority, source, created_at, updated_at\n ) VALUES (?, ?, ?, ?, ?, ?, ?)").run(a, o, r, s, c, l, l), d = Tb(e, Number(u.lastInsertRowid));
16396
16444
  if (!d) throw Error("project_scope_mapping insert returned no row");
16397
16445
  return d;
16398
16446
  }
16399
- function jb(e, t) {
16447
+ function Pb(e, t) {
16400
16448
  if (!Number.isInteger(t) || t <= 0) throw Error("id must be a positive integer");
16401
16449
  let n = e.prepare("DELETE FROM project_scope_mappings WHERE id = ?").run(t);
16402
16450
  return Number(n.changes ?? 0) > 0;
16403
16451
  }
16404
16452
  //#endregion
16405
16453
  //#region src/raw-event-sweeper.ts
16406
- var Mb = 60;
16407
- function Nb(e, t) {
16454
+ var Fb = 60;
16455
+ function Ib(e, t) {
16408
16456
  let n = process.env[e];
16409
16457
  if (n == null) return t;
16410
16458
  let r = Number.parseInt(n, 10);
16411
16459
  return Number.isFinite(r) ? r : t;
16412
16460
  }
16413
- function Pb(e) {
16461
+ function Lb(e) {
16414
16462
  let t = (process.env[e] ?? "1").trim().toLowerCase();
16415
16463
  return t === "0" || t === "false" || t === "off";
16416
16464
  }
16417
- var Fb = class {
16465
+ var Rb = class {
16418
16466
  store;
16419
16467
  ingestOpts;
16420
16468
  active = !1;
@@ -16432,7 +16480,7 @@ var Fb = class {
16432
16480
  this.store = e, this.ingestOpts = t;
16433
16481
  }
16434
16482
  enabled() {
16435
- return !Pb("CODEMEM_RAW_EVENTS_SWEEPER");
16483
+ return !Lb("CODEMEM_RAW_EVENTS_SWEEPER");
16436
16484
  }
16437
16485
  intervalMs() {
16438
16486
  let e = process.env.CODEMEM_RAW_EVENTS_SWEEPER_INTERVAL_MS;
@@ -16444,31 +16492,31 @@ var Fb = class {
16444
16492
  return Number.isFinite(n) && n > 0 ? Math.max(1e3, n * 1e3) : 3e4;
16445
16493
  }
16446
16494
  idleMs() {
16447
- return Nb("CODEMEM_RAW_EVENTS_SWEEPER_IDLE_MS", 12e4);
16495
+ return Ib("CODEMEM_RAW_EVENTS_SWEEPER_IDLE_MS", 12e4);
16448
16496
  }
16449
16497
  limit() {
16450
- return Nb("CODEMEM_RAW_EVENTS_SWEEPER_LIMIT", 25);
16498
+ return Ib("CODEMEM_RAW_EVENTS_SWEEPER_LIMIT", 25);
16451
16499
  }
16452
16500
  workerMaxEvents() {
16453
- let e = Nb("CODEMEM_RAW_EVENTS_WORKER_MAX_EVENTS", 100);
16501
+ let e = Ib("CODEMEM_RAW_EVENTS_WORKER_MAX_EVENTS", 100);
16454
16502
  return e <= 0 ? null : e;
16455
16503
  }
16456
16504
  retentionMs() {
16457
- return Nb("CODEMEM_RAW_EVENTS_RETENTION_MS", 0);
16505
+ return Ib("CODEMEM_RAW_EVENTS_RETENTION_MS", 0);
16458
16506
  }
16459
16507
  autoFlushEnabled() {
16460
16508
  return (process.env.CODEMEM_RAW_EVENTS_AUTO_FLUSH ?? "").trim() === "1";
16461
16509
  }
16462
16510
  debounceMs() {
16463
- return Nb("CODEMEM_RAW_EVENTS_DEBOUNCE_MS", 6e4);
16511
+ return Ib("CODEMEM_RAW_EVENTS_DEBOUNCE_MS", 6e4);
16464
16512
  }
16465
16513
  stuckBatchMs() {
16466
- return Nb("CODEMEM_RAW_EVENTS_STUCK_BATCH_MS", 3e5);
16514
+ return Ib("CODEMEM_RAW_EVENTS_STUCK_BATCH_MS", 3e5);
16467
16515
  }
16468
16516
  handleAuthError(e) {
16469
- if (this.authBackoffUntil = Date.now() / 1e3 + Mb, !this.authErrorLogged) {
16517
+ if (this.authBackoffUntil = Date.now() / 1e3 + Fb, !this.authErrorLogged) {
16470
16518
  this.authErrorLogged = !0;
16471
- let t = `codemem: observer auth error — backing off for ${Mb}s. Refresh your provider credentials or update observer_provider in settings. (${e.message})`;
16519
+ let t = `codemem: observer auth error — backing off for ${Fb}s. Refresh your provider credentials or update observer_provider in settings. (${e.message})`;
16472
16520
  console.error(t);
16473
16521
  }
16474
16522
  }
@@ -16652,16 +16700,16 @@ var Fb = class {
16652
16700
  }
16653
16701
  }
16654
16702
  }
16655
- }, Ib = "memory_ref_backfill", Lb = "mi.active = 1\n AND (\n (\n (\n (json_valid(mi.files_read) AND json_type(mi.files_read) = 'array' AND json_array_length(mi.files_read) > 0)\n OR\n (json_valid(mi.files_modified) AND json_type(mi.files_modified) = 'array' AND json_array_length(mi.files_modified) > 0)\n )\n AND NOT EXISTS (\n SELECT 1 FROM memory_file_refs mfr WHERE mfr.memory_id = mi.id\n )\n )\n OR\n (\n json_valid(mi.concepts)\n AND json_type(mi.concepts) = 'array'\n AND json_array_length(mi.concepts) > 0\n AND NOT EXISTS (\n SELECT 1 FROM memory_concept_refs mcr WHERE mcr.memory_id = mi.id\n )\n )\n )";
16656
- function Rb(e) {
16703
+ }, zb = "memory_ref_backfill", Bb = "mi.active = 1\n AND (\n (\n (\n (json_valid(mi.files_read) AND json_type(mi.files_read) = 'array' AND json_array_length(mi.files_read) > 0)\n OR\n (json_valid(mi.files_modified) AND json_type(mi.files_modified) = 'array' AND json_array_length(mi.files_modified) > 0)\n )\n AND NOT EXISTS (\n SELECT 1 FROM memory_file_refs mfr WHERE mfr.memory_id = mi.id\n )\n )\n OR\n (\n json_valid(mi.concepts)\n AND json_type(mi.concepts) = 'array'\n AND json_array_length(mi.concepts) > 0\n AND NOT EXISTS (\n SELECT 1 FROM memory_concept_refs mcr WHERE mcr.memory_id = mi.id\n )\n )\n )";
16704
+ function Vb(e) {
16657
16705
  return e.prepare(`SELECT 1 FROM memory_items mi
16658
- WHERE ${Lb}
16706
+ WHERE ${Bb}
16659
16707
  LIMIT 1`).get() != null;
16660
16708
  }
16661
- function zb(e) {
16709
+ function Hb(e) {
16662
16710
  return Q(e, "memory_ref_backfill")?.metadata ?? {};
16663
16711
  }
16664
- function Bb(e) {
16712
+ function Ub(e) {
16665
16713
  if (!e) return null;
16666
16714
  try {
16667
16715
  let t = JSON.parse(e);
@@ -16669,17 +16717,17 @@ function Bb(e) {
16669
16717
  } catch {}
16670
16718
  return null;
16671
16719
  }
16672
- async function Vb(e, t = {}) {
16673
- let n = Q(e, Ib), r = zb(e), i = Math.max(1, t.batchSize ?? 50), a = !n || n.status === "completed" || n.status === "failed", o = a ? 0 : Number(r.last_cursor_id ?? 0), s = e.prepare(`SELECT mi.id, mi.files_read, mi.files_modified, mi.concepts
16720
+ async function Wb(e, t = {}) {
16721
+ let n = Q(e, zb), r = Hb(e), i = Math.max(1, t.batchSize ?? 50), a = !n || n.status === "completed" || n.status === "failed", o = a ? 0 : Number(r.last_cursor_id ?? 0), s = e.prepare(`SELECT mi.id, mi.files_read, mi.files_modified, mi.concepts
16674
16722
  FROM memory_items mi
16675
16723
  WHERE mi.id > ?
16676
- AND ${Lb}
16724
+ AND ${Bb}
16677
16725
  ORDER BY mi.id ASC
16678
16726
  LIMIT ?`).all(o, i);
16679
16727
  if (s.length === 0) {
16680
16728
  if (n && n.status !== "completed") {
16681
16729
  let t = Number(r.processed ?? 0);
16682
- Yr(e, Ib, {
16730
+ Yr(e, zb, {
16683
16731
  message: "Ref backfill complete",
16684
16732
  progressCurrent: t,
16685
16733
  progressTotal: Number(r.total_backfillable ?? t),
@@ -16695,9 +16743,9 @@ async function Vb(e, t = {}) {
16695
16743
  let c = a ? 0 : Number(r.processed ?? 0), l = Number(r.total_backfillable ?? 0);
16696
16744
  if (a) {
16697
16745
  let t = e.prepare(`SELECT COUNT(*) AS cnt FROM memory_items mi
16698
- WHERE ${Lb}`).get().cnt;
16746
+ WHERE ${Bb}`).get().cnt;
16699
16747
  qr(e, {
16700
- kind: Ib,
16748
+ kind: zb,
16701
16749
  title: "Backfilling memory file/concept refs",
16702
16750
  message: `Backfilling refs for ${t} memories`,
16703
16751
  progressTotal: t,
@@ -16710,7 +16758,7 @@ async function Vb(e, t = {}) {
16710
16758
  }), l = t;
16711
16759
  }
16712
16760
  let u = e.prepare("INSERT OR IGNORE INTO memory_file_refs (memory_id, file_path, relation) VALUES (?, ?, ?)"), d = e.prepare("INSERT OR IGNORE INTO memory_concept_refs (memory_id, concept) VALUES (?, ?)"), f = e.transaction((e) => {
16713
- let t = Bb(e.files_read), n = Bb(e.files_modified), r = Bb(e.concepts);
16761
+ let t = Ub(e.files_read), n = Ub(e.files_modified), r = Ub(e.concepts);
16714
16762
  if (t) for (let n of t) n && u.run(e.id, n, "read");
16715
16763
  if (n) for (let t of n) t && u.run(e.id, t, "modified");
16716
16764
  if (r) for (let t of r) {
@@ -16721,8 +16769,8 @@ async function Vb(e, t = {}) {
16721
16769
  for (let e of s) f(e);
16722
16770
  let p = c + s.length, m = s.length < i, h = s[s.length - 1].id;
16723
16771
  if (m) {
16724
- let t = Number(zb(e).total_backfillable ?? l ?? p);
16725
- return Yr(e, Ib, {
16772
+ let t = Number(Hb(e).total_backfillable ?? l ?? p);
16773
+ return Yr(e, zb, {
16726
16774
  message: "Ref backfill complete",
16727
16775
  progressCurrent: t,
16728
16776
  progressTotal: t,
@@ -16734,7 +16782,7 @@ async function Vb(e, t = {}) {
16734
16782
  }
16735
16783
  }), !1;
16736
16784
  }
16737
- return Jr(e, Ib, {
16785
+ return Jr(e, zb, {
16738
16786
  message: `Backfilled refs for ${p} of ${l} memories`,
16739
16787
  progressCurrent: p,
16740
16788
  progressTotal: l,
@@ -16746,7 +16794,7 @@ async function Vb(e, t = {}) {
16746
16794
  }
16747
16795
  }), !0;
16748
16796
  }
16749
- var Hb = class {
16797
+ var Gb = class {
16750
16798
  dbPath;
16751
16799
  signal;
16752
16800
  batchSize;
@@ -16776,14 +16824,14 @@ var Hb = class {
16776
16824
  if (!this.active || this.signal?.aborted) return;
16777
16825
  let e = null;
16778
16826
  try {
16779
- e = Mn(this.dbPath), await Vb(e, { batchSize: this.batchSize }) || (this.active = !1);
16827
+ e = Mn(this.dbPath), await Wb(e, { batchSize: this.batchSize }) || (this.active = !1);
16780
16828
  } catch (t) {
16781
- e && Xr(e, Ib, t instanceof Error ? t.message : String(t)), console.warn("Ref backfill runner failed", t);
16829
+ e && Xr(e, zb, t instanceof Error ? t.message : String(t)), console.warn("Ref backfill runner failed", t);
16782
16830
  } finally {
16783
16831
  e?.close();
16784
16832
  }
16785
16833
  }
16786
- }, Ub = "session_context_backfill", Wb = [
16834
+ }, Kb = "session_context_backfill", qb = [
16787
16835
  "firstPrompt",
16788
16836
  "promptCount",
16789
16837
  "toolCount",
@@ -16791,20 +16839,20 @@ var Hb = class {
16791
16839
  "filesModified",
16792
16840
  "filesRead"
16793
16841
  ];
16794
- function Gb(e) {
16842
+ function Jb(e) {
16795
16843
  let t = e.prepare("SELECT COUNT(*) AS c FROM sessions\n WHERE json_extract(metadata_json, '$.session_context.flusher') = 'raw_events'").get();
16796
16844
  return Number(t?.c ?? 0);
16797
16845
  }
16798
- function Kb(e, t, n) {
16846
+ function Yb(e, t, n) {
16799
16847
  return e.prepare("SELECT\n s.id AS id,\n s.metadata_json AS metadata_json,\n os.source AS source,\n os.stream_id AS stream_id\n FROM sessions s\n LEFT JOIN (\n SELECT session_id, source, stream_id\n FROM opencode_sessions\n GROUP BY session_id\n ) os ON os.session_id = s.id\n WHERE s.id > ?\n AND json_extract(s.metadata_json, '$.session_context.flusher') = 'raw_events'\n ORDER BY s.id ASC\n LIMIT ?").all(t, n);
16800
16848
  }
16801
- function qb(e, t, n) {
16849
+ function Xb(e, t, n) {
16802
16850
  return e.prepare("SELECT event_seq, event_type, ts_wall_ms, ts_mono_ms, payload_json, event_id\n FROM raw_events\n WHERE source = ? AND stream_id = ?\n ORDER BY event_seq ASC").all(t, n).map((e) => {
16803
16851
  let t = JSON.parse(e.payload_json);
16804
16852
  return t.type = t.type || e.event_type, t.timestamp_wall_ms = e.ts_wall_ms, t.timestamp_mono_ms = e.ts_mono_ms, t.event_seq = e.event_seq, t.event_id = e.event_id, t;
16805
16853
  });
16806
16854
  }
16807
- function Jb(e) {
16855
+ function Zb(e) {
16808
16856
  if (!e) return {};
16809
16857
  try {
16810
16858
  let t = JSON.parse(e);
@@ -16812,42 +16860,42 @@ function Jb(e) {
16812
16860
  } catch {}
16813
16861
  return {};
16814
16862
  }
16815
- function Yb(e) {
16863
+ function Qb(e) {
16816
16864
  return Array.isArray(e) ? [...e].sort() : e ?? null;
16817
16865
  }
16818
- function Xb(e, t) {
16819
- for (let n of Wb) {
16820
- let r = Yb(e[n]), i = Yb(t[n]);
16866
+ function $b(e, t) {
16867
+ for (let n of qb) {
16868
+ let r = Qb(e[n]), i = Qb(t[n]);
16821
16869
  if (JSON.stringify(r) !== JSON.stringify(i)) return !0;
16822
16870
  }
16823
16871
  return !1;
16824
16872
  }
16825
- function Zb(e, t) {
16873
+ function ex(e, t) {
16826
16874
  let n = { ...e };
16827
- for (let e of Wb) {
16875
+ for (let e of qb) {
16828
16876
  let r = t[e];
16829
16877
  r === void 0 ? delete n[e] : n[e] = r;
16830
16878
  }
16831
16879
  return n;
16832
16880
  }
16833
- function Qb(e, t, n) {
16881
+ function tx(e, t, n) {
16834
16882
  let r = 0, i = 0, a = 0, o = 0, s = t.at(-1)?.id ?? 0, c = e.prepare("UPDATE sessions SET metadata_json = ? WHERE id = ?");
16835
16883
  for (let n of t) {
16836
16884
  if (s = n.id, !n.source || !n.stream_id) {
16837
16885
  a += 1;
16838
16886
  continue;
16839
16887
  }
16840
- let t = qb(e, n.source, n.stream_id);
16888
+ let t = Xb(e, n.source, n.stream_id);
16841
16889
  if (t.length === 0) {
16842
16890
  i += 1;
16843
16891
  continue;
16844
16892
  }
16845
- let l = Ev(q_(t)), u = Jb(n.metadata_json), d = u.session_context, f = d && typeof d == "object" ? d : {};
16846
- if (!Xb(f, l)) {
16893
+ let l = Ev(q_(t)), u = Zb(n.metadata_json), d = u.session_context, f = d && typeof d == "object" ? d : {};
16894
+ if (!$b(f, l)) {
16847
16895
  o += 1;
16848
16896
  continue;
16849
16897
  }
16850
- let p = Zb(f, l), m = {
16898
+ let p = ex(f, l), m = {
16851
16899
  ...u,
16852
16900
  session_context: p
16853
16901
  };
@@ -16863,14 +16911,14 @@ function Qb(e, t, n) {
16863
16911
  exhausted: t.length < n
16864
16912
  };
16865
16913
  }
16866
- function $b(e) {
16867
- return Q(e, "session_context_backfill")?.status === "completed" ? !1 : Gb(e) > 0;
16914
+ function nx(e) {
16915
+ return Q(e, "session_context_backfill")?.status === "completed" ? !1 : Jb(e) > 0;
16868
16916
  }
16869
- async function ex(e, t = {}) {
16870
- let n = Math.max(1, t.batchSize ?? 100), r = Q(e, Ub), i = r?.metadata ?? {}, a = !r || r.status === "completed" || r.status === "failed", o = a ? 0 : Number(i.last_cursor_id ?? 0), s = a ? Gb(e) : Number(i.total_candidates ?? Gb(e));
16917
+ async function rx(e, t = {}) {
16918
+ let n = Math.max(1, t.batchSize ?? 100), r = Q(e, Kb), i = r?.metadata ?? {}, a = !r || r.status === "completed" || r.status === "failed", o = a ? 0 : Number(i.last_cursor_id ?? 0), s = a ? Jb(e) : Number(i.total_candidates ?? Jb(e));
16871
16919
  if (a && s <= 0) return !1;
16872
16920
  a && qr(e, {
16873
- kind: Ub,
16921
+ kind: Kb,
16874
16922
  title: "Backfilling session context",
16875
16923
  message: `Rebuilding session_context for ${s} raw-event sessions`,
16876
16924
  progressTotal: s,
@@ -16884,11 +16932,11 @@ async function ex(e, t = {}) {
16884
16932
  unchanged_sessions: 0
16885
16933
  }
16886
16934
  });
16887
- let c = Kb(e, o, n);
16935
+ let c = Yb(e, o, n);
16888
16936
  if (c.length === 0) {
16889
16937
  let t = Q(e, "session_context_backfill")?.metadata ?? {};
16890
- return Yr(e, Ub, {
16891
- message: tx(t),
16938
+ return Yr(e, Kb, {
16939
+ message: ix(t),
16892
16940
  progressCurrent: Number(t.processed_sessions ?? 0),
16893
16941
  progressTotal: Number(t.total_candidates ?? t.processed_sessions ?? 0),
16894
16942
  metadata: {
@@ -16897,7 +16945,7 @@ async function ex(e, t = {}) {
16897
16945
  }
16898
16946
  }), !1;
16899
16947
  }
16900
- let l = Qb(e, c, n), u = Q(e, "session_context_backfill")?.metadata ?? {}, d = Number(u.processed_sessions ?? 0) + l.processed, f = Number(u.rewritten_sessions ?? 0) + l.rewritten, p = Number(u.skipped_no_events ?? 0) + l.skippedNoEvents, m = Number(u.skipped_no_bridge ?? 0) + l.skippedNoBridge, h = Number(u.unchanged_sessions ?? 0) + l.unchanged, g = {
16948
+ let l = tx(e, c, n), u = Q(e, "session_context_backfill")?.metadata ?? {}, d = Number(u.processed_sessions ?? 0) + l.processed, f = Number(u.rewritten_sessions ?? 0) + l.rewritten, p = Number(u.skipped_no_events ?? 0) + l.skippedNoEvents, m = Number(u.skipped_no_bridge ?? 0) + l.skippedNoBridge, h = Number(u.unchanged_sessions ?? 0) + l.unchanged, g = {
16901
16949
  last_cursor_id: l.lastCursorId,
16902
16950
  total_candidates: Number(u.total_candidates ?? s),
16903
16951
  processed_sessions: d,
@@ -16906,12 +16954,12 @@ async function ex(e, t = {}) {
16906
16954
  skipped_no_bridge: m,
16907
16955
  unchanged_sessions: h
16908
16956
  };
16909
- return l.exhausted ? (Yr(e, Ub, {
16910
- message: tx(g),
16957
+ return l.exhausted ? (Yr(e, Kb, {
16958
+ message: ix(g),
16911
16959
  progressCurrent: d,
16912
16960
  progressTotal: Number(g.total_candidates ?? d),
16913
16961
  metadata: g
16914
- }), !1) : (Jr(e, Ub, {
16962
+ }), !1) : (Jr(e, Kb, {
16915
16963
  status: "running",
16916
16964
  message: `Rebuilt session_context for ${f} of ${d} scanned sessions`,
16917
16965
  progressCurrent: d,
@@ -16919,11 +16967,11 @@ async function ex(e, t = {}) {
16919
16967
  metadata: g
16920
16968
  }), !0);
16921
16969
  }
16922
- function tx(e) {
16970
+ function ix(e) {
16923
16971
  let t = Number(e.rewritten_sessions ?? 0), n = Number(e.processed_sessions ?? 0), r = Number(e.skipped_no_events ?? 0) + Number(e.skipped_no_bridge ?? 0);
16924
16972
  return n === 0 ? "No raw-event sessions required session_context backfill" : t === 0 ? `Scanned ${n} sessions, no session_context rewrite required` : `Rebuilt session_context for ${t} of ${n} sessions${r > 0 ? ` (${r} skipped)` : ""}`;
16925
16973
  }
16926
- var nx = class {
16974
+ var ax = class {
16927
16975
  dbPath;
16928
16976
  signal;
16929
16977
  batchSize;
@@ -16953,25 +17001,25 @@ var nx = class {
16953
17001
  if (!this.active || this.signal?.aborted) return;
16954
17002
  let e = null;
16955
17003
  try {
16956
- e = Mn(this.dbPath), await ex(e, { batchSize: this.batchSize }) || (this.active = !1);
17004
+ e = Mn(this.dbPath), await rx(e, { batchSize: this.batchSize }) || (this.active = !1);
16957
17005
  } catch (t) {
16958
- e && Xr(e, Ub, t instanceof Error ? t.message : String(t)), console.warn("Session-context backfill runner failed", t);
17006
+ e && Xr(e, Kb, t instanceof Error ? t.message : String(t)), console.warn("Session-context backfill runner failed", t);
16959
17007
  } finally {
16960
17008
  e?.close();
16961
17009
  }
16962
17010
  }
16963
- }, rx = "session_summary_dedup_backfill";
16964
- function ix(e) {
17011
+ }, ox = "session_summary_dedup_backfill";
17012
+ function sx(e) {
16965
17013
  let t = e.prepare("SELECT COUNT(*) AS n FROM (\n SELECT session_id\n FROM memory_items\n WHERE active = 1\n AND kind = 'session_summary'\n AND json_extract(metadata_json, '$.source') = 'observer_summary'\n GROUP BY session_id\n HAVING COUNT(*) > 1\n )").get();
16966
17014
  return Number(t?.n ?? 0);
16967
17015
  }
16968
- function ax(e) {
16969
- return ix(e) > 0;
17016
+ function cx(e) {
17017
+ return sx(e) > 0;
16970
17018
  }
16971
- function ox(e) {
17019
+ function lx(e) {
16972
17020
  return Q(e, "session_summary_dedup_backfill")?.metadata ?? {};
16973
17021
  }
16974
- function sx(e, t, n) {
17022
+ function ux(e, t, n) {
16975
17023
  let r = e.prepare("SELECT session_id\n FROM memory_items\n WHERE active = 1\n AND kind = 'session_summary'\n AND json_extract(metadata_json, '$.source') = 'observer_summary'\n AND session_id > ?\n GROUP BY session_id\n HAVING COUNT(*) > 1\n ORDER BY session_id ASC\n LIMIT ?").all(t, n);
16976
17024
  if (r.length === 0) return [];
16977
17025
  let i = e.prepare("SELECT id, rev, metadata_json, created_at\n FROM memory_items\n WHERE session_id = ?\n AND active = 1\n AND kind = 'session_summary'\n AND json_extract(metadata_json, '$.source') = 'observer_summary'\n ORDER BY created_at DESC, id DESC"), a = [];
@@ -16987,7 +17035,7 @@ function sx(e, t, n) {
16987
17035
  }
16988
17036
  return a;
16989
17037
  }
16990
- function cx(e, t, n) {
17038
+ function dx(e, t, n) {
16991
17039
  let r = (/* @__PURE__ */ new Date()).toISOString(), i = e.prepare("UPDATE memory_items\n SET active = 0,\n deleted_at = ?,\n updated_at = ?,\n metadata_json = ?,\n rev = ?\n WHERE id = ?"), a = 0;
16992
17040
  for (let o of t.superseded) {
16993
17041
  let s = Un(o.metadata_json);
@@ -17003,9 +17051,9 @@ function cx(e, t, n) {
17003
17051
  }
17004
17052
  return a;
17005
17053
  }
17006
- async function lx(e, t = {}) {
17007
- let n = Math.max(1, t.batchSize ?? 50), r = t.deviceId ?? "local", i = Q(e, rx), a = ox(e), o = !i || i.status === "completed" || i.status === "failed", s = o ? 0 : Number(a.last_session_id ?? 0), c = sx(e, s, n), l = o ? 0 : Number(a.processed_sessions ?? 0), u = o ? 0 : Number(a.superseded_rows ?? 0);
17008
- if (c.length === 0) return i && i.status !== "completed" && Yr(e, rx, {
17054
+ async function fx(e, t = {}) {
17055
+ let n = Math.max(1, t.batchSize ?? 50), r = t.deviceId ?? "local", i = Q(e, ox), a = lx(e), o = !i || i.status === "completed" || i.status === "failed", s = o ? 0 : Number(a.last_session_id ?? 0), c = ux(e, s, n), l = o ? 0 : Number(a.processed_sessions ?? 0), u = o ? 0 : Number(a.superseded_rows ?? 0);
17056
+ if (c.length === 0) return i && i.status !== "completed" && Yr(e, ox, {
17009
17057
  message: u > 0 ? `Session-summary dedup complete (${u} rows superseded)` : "Session-summary dedup complete",
17010
17058
  progressCurrent: l,
17011
17059
  progressTotal: Number(a.total_sessions ?? l),
@@ -17015,9 +17063,9 @@ async function lx(e, t = {}) {
17015
17063
  }
17016
17064
  }), !1;
17017
17065
  if (!i || i.status === "completed" || i.status === "failed") {
17018
- let t = ix(e);
17066
+ let t = sx(e);
17019
17067
  qr(e, {
17020
- kind: rx,
17068
+ kind: ox,
17021
17069
  title: "Deduplicating historical session summaries",
17022
17070
  message: `Cleaning up ${t} sessions with duplicate observer summaries`,
17023
17071
  progressTotal: t,
@@ -17032,10 +17080,10 @@ async function lx(e, t = {}) {
17032
17080
  }
17033
17081
  let d = 0, f = s;
17034
17082
  e.transaction(() => {
17035
- for (let t of c) d += cx(e, t, r), t.session_id > f && (f = t.session_id);
17083
+ for (let t of c) d += dx(e, t, r), t.session_id > f && (f = t.session_id);
17036
17084
  })();
17037
- let p = l + c.length, m = u + d, h = ix(e), g = Math.max(Number(a.total_sessions ?? p), p + h);
17038
- return h === 0 ? (Yr(e, rx, {
17085
+ let p = l + c.length, m = u + d, h = sx(e), g = Math.max(Number(a.total_sessions ?? p), p + h);
17086
+ return h === 0 ? (Yr(e, ox, {
17039
17087
  message: `Session-summary dedup complete (${m} rows superseded across ${p} sessions)`,
17040
17088
  progressCurrent: p,
17041
17089
  progressTotal: g,
@@ -17045,7 +17093,7 @@ async function lx(e, t = {}) {
17045
17093
  superseded_rows: m,
17046
17094
  last_session_id: f
17047
17095
  }
17048
- }), !1) : (Jr(e, rx, {
17096
+ }), !1) : (Jr(e, ox, {
17049
17097
  message: `Deduplicated ${p} of ${g} sessions (${m} rows superseded)`,
17050
17098
  progressCurrent: p,
17051
17099
  progressTotal: g,
@@ -17057,7 +17105,7 @@ async function lx(e, t = {}) {
17057
17105
  }
17058
17106
  }), !0);
17059
17107
  }
17060
- var ux = class {
17108
+ var px = class {
17061
17109
  dbPath;
17062
17110
  signal;
17063
17111
  batchSize;
@@ -17088,21 +17136,21 @@ var ux = class {
17088
17136
  if (!this.active || this.signal?.aborted) return;
17089
17137
  let e = null;
17090
17138
  try {
17091
- e = Mn(this.dbPath), await lx(e, {
17139
+ e = Mn(this.dbPath), await fx(e, {
17092
17140
  batchSize: this.batchSize,
17093
17141
  deviceId: this.deviceId
17094
17142
  }) || (this.active = !1);
17095
17143
  } catch (t) {
17096
- e && Xr(e, rx, t instanceof Error ? t.message : String(t)), console.warn("Summary-dedup backfill runner failed", t);
17144
+ e && Xr(e, ox, t instanceof Error ? t.message : String(t)), console.warn("Summary-dedup backfill runner failed", t);
17097
17145
  } finally {
17098
17146
  e?.close();
17099
17147
  }
17100
17148
  }
17101
- }, dx = Te(import.meta.url), fx = "_codemem._tcp.local.";
17102
- function px(e) {
17149
+ }, mx = Te(import.meta.url), hx = "_codemem._tcp.local.";
17150
+ function gx(e) {
17103
17151
  return e.mdns.length === 0 ? El(e.stored, []) : El(e.mdns, e.stored);
17104
17152
  }
17105
- function mx(e, t) {
17153
+ function _x(e, t) {
17106
17154
  let n = P(e, { schema: H }).select({ addresses_json: Y.addresses_json }).from(Y).where(A(Y.peer_device_id, t)).get();
17107
17155
  if (!n?.addresses_json) return [];
17108
17156
  try {
@@ -17112,8 +17160,8 @@ function mx(e, t) {
17112
17160
  return [];
17113
17161
  }
17114
17162
  }
17115
- function hx(e, t, n, r) {
17116
- let i = El(mx(e, t), n), a = (/* @__PURE__ */ new Date()).toISOString(), o = JSON.stringify(i);
17163
+ function vx(e, t, n, r) {
17164
+ let i = El(_x(e, t), n), a = (/* @__PURE__ */ new Date()).toISOString(), o = JSON.stringify(i);
17117
17165
  return P(e, { schema: H }).insert(Y).values({
17118
17166
  peer_device_id: t,
17119
17167
  name: r?.name ?? null,
@@ -17133,7 +17181,7 @@ function hx(e, t, n, r) {
17133
17181
  }
17134
17182
  }).run(), i;
17135
17183
  }
17136
- function gx(e, t, n) {
17184
+ function yx(e, t, n) {
17137
17185
  let r = P(e, { schema: H }), i = (/* @__PURE__ */ new Date()).toISOString();
17138
17186
  r.insert(ft).values({
17139
17187
  peer_device_id: t,
@@ -17148,10 +17196,10 @@ function gx(e, t, n) {
17148
17196
  last_error: null
17149
17197
  }).where(A(Y.peer_device_id, t)).run() : r.update(Y).set({ last_error: n.error ?? null }).where(A(Y.peer_device_id, t)).run();
17150
17198
  }
17151
- function _x(e, t, n) {
17199
+ function bx(e, t, n) {
17152
17200
  let r = Cl(n ?? ""), i = (/* @__PURE__ */ new Date()).toISOString();
17153
17201
  return e.transaction((t, n, r) => {
17154
- let i = mx(e, t), a = n ? i.filter((e) => Cl(e) !== n) : i, o = n ? [n, ...a] : i;
17202
+ let i = _x(e, t), a = n ? i.filter((e) => Cl(e) !== n) : i, o = n ? [n, ...a] : i;
17155
17203
  return P(e, { schema: H }).update(Y).set({
17156
17204
  addresses_json: JSON.stringify(o),
17157
17205
  last_sync_at: r,
@@ -17160,23 +17208,23 @@ function _x(e, t, n) {
17160
17208
  }).where(A(Y.peer_device_id, t)).run(), o;
17161
17209
  }).immediate(t, r, i);
17162
17210
  }
17163
- function vx(e, t, n) {
17211
+ function xx(e, t, n) {
17164
17212
  let r = n.include === null ? null : JSON.stringify(n.include), i = n.exclude === null ? null : JSON.stringify(n.exclude);
17165
17213
  P(e, { schema: H }).update(Y).set({
17166
17214
  projects_include_json: r,
17167
17215
  projects_exclude_json: i
17168
17216
  }).where(A(Y.peer_device_id, t)).run();
17169
17217
  }
17170
- function yx(e, t, n) {
17218
+ function Sx(e, t, n) {
17171
17219
  P(e, { schema: H }).update(Y).set({ claimed_local_actor: +!!n }).where(A(Y.peer_device_id, t)).run();
17172
17220
  }
17173
- function bx(e) {
17221
+ function Cx(e) {
17174
17222
  let t = {};
17175
17223
  for (let [n, r] of Object.entries(e)) t[n] = r instanceof Uint8Array ? r : String(r);
17176
17224
  return t;
17177
17225
  }
17178
- var xx = "codemem";
17179
- function Sx() {
17226
+ var wx = "codemem";
17227
+ function Tx() {
17180
17228
  let e = process.env.CODEMEM_SYNC_MDNS;
17181
17229
  if (e) return e === "1" || e.toLowerCase() === "true";
17182
17230
  try {
@@ -17185,9 +17233,9 @@ function Sx() {
17185
17233
  return !1;
17186
17234
  }
17187
17235
  }
17188
- function Cx() {
17236
+ function Ex() {
17189
17237
  try {
17190
- let e = dx("bonjour-service"), t = e.Bonjour ?? e.default;
17238
+ let e = mx("bonjour-service"), t = e.Bonjour ?? e.default;
17191
17239
  return t ? new t(void 0, (e) => {
17192
17240
  console.warn("[codemem] mDNS runtime error (non-fatal):", e?.message ?? e);
17193
17241
  }) : null;
@@ -17195,40 +17243,40 @@ function Cx() {
17195
17243
  return null;
17196
17244
  }
17197
17245
  }
17198
- var wx = null, Tx = 0;
17199
- function Ex() {
17200
- if (wx) return Tx += 1, wx;
17201
- let e = Cx();
17202
- return e ? (wx = e, Tx = 1, wx) : null;
17203
- }
17204
- function Dx() {
17205
- if (!wx || (Tx = Math.max(0, Tx - 1), Tx > 0)) return;
17206
- let e = wx;
17207
- wx = null;
17246
+ var Dx = null, Ox = 0;
17247
+ function kx() {
17248
+ if (Dx) return Ox += 1, Dx;
17249
+ let e = Ex();
17250
+ return e ? (Dx = e, Ox = 1, Dx) : null;
17251
+ }
17252
+ function Ax() {
17253
+ if (!Dx || (Ox = Math.max(0, Ox - 1), Ox > 0)) return;
17254
+ let e = Dx;
17255
+ Dx = null;
17208
17256
  try {
17209
17257
  e.destroy();
17210
17258
  } catch {}
17211
17259
  }
17212
- function Ox(e, t) {
17213
- if (!Sx() || !e || !t || !Number.isFinite(t)) return { close() {} };
17214
- let n = Ex();
17260
+ function jx(e, t) {
17261
+ if (!Tx() || !e || !t || !Number.isFinite(t)) return { close() {} };
17262
+ let n = kx();
17215
17263
  if (!n) return { close() {} };
17216
17264
  let r = null;
17217
17265
  try {
17218
17266
  r = n.publish({
17219
17267
  name: `codemem-${e.slice(0, 12)}`,
17220
- type: xx,
17268
+ type: wx,
17221
17269
  port: t,
17222
17270
  txt: { device_id: e }
17223
17271
  });
17224
17272
  } catch {
17225
- return Dx(), { close() {} };
17273
+ return Ax(), { close() {} };
17226
17274
  }
17227
17275
  let i = !1;
17228
17276
  return { close() {
17229
17277
  if (i) return;
17230
17278
  i = !0;
17231
- let e = () => Dx();
17279
+ let e = () => Ax();
17232
17280
  try {
17233
17281
  r?.stop(() => e());
17234
17282
  } catch {
@@ -17236,13 +17284,13 @@ function Ox(e, t) {
17236
17284
  }
17237
17285
  } };
17238
17286
  }
17239
- async function kx(e = 1500) {
17240
- if (!Sx()) return [];
17241
- let t = Ex();
17287
+ async function Mx(e = 1500) {
17288
+ if (!Tx()) return [];
17289
+ let t = kx();
17242
17290
  if (!t) return [];
17243
17291
  let n = [], r = /* @__PURE__ */ new Set(), i = !0, a = null;
17244
17292
  try {
17245
- a = t.find({ type: xx }, (e) => {
17293
+ a = t.find({ type: wx }, (e) => {
17246
17294
  if (!i) return;
17247
17295
  let t = `${e.name}|${e.host ?? e.fqdn ?? ""}|${e.port}`;
17248
17296
  if (r.has(t)) return;
@@ -17253,7 +17301,7 @@ async function kx(e = 1500) {
17253
17301
  host: (e.host || e.fqdn || "").replace(/\.$/, ""),
17254
17302
  port: e.port,
17255
17303
  address: o,
17256
- properties: bx(s)
17304
+ properties: Cx(s)
17257
17305
  });
17258
17306
  }), await new Promise((t) => setTimeout(t, Math.max(100, e)));
17259
17307
  } finally {
@@ -17261,11 +17309,11 @@ async function kx(e = 1500) {
17261
17309
  try {
17262
17310
  a?.stop();
17263
17311
  } catch {}
17264
- Dx();
17312
+ Ax();
17265
17313
  }
17266
17314
  return n;
17267
17315
  }
17268
- function Ax(e, t) {
17316
+ function Nx(e, t) {
17269
17317
  let n = [];
17270
17318
  for (let r of t) {
17271
17319
  let t = r.properties ?? {}, i = t.device_id ?? t.device_id;
@@ -17282,41 +17330,41 @@ function Ax(e, t) {
17282
17330
  }
17283
17331
  //#endregion
17284
17332
  //#region src/sync-pass.ts
17285
- var jx = 1048576, Mx = !1, Nx = 500, Px = 2e3, Fx = "2";
17286
- function Ix(e, t) {
17333
+ var Px = 1048576, Fx = !1, Ix = 500, Lx = 2e3, Rx = "2";
17334
+ function zx(e, t) {
17287
17335
  return !t || !t.includes("|") ? !1 : e ? t > e : !0;
17288
17336
  }
17289
- function Lx(e) {
17337
+ function Bx(e) {
17290
17338
  if (!e) return null;
17291
17339
  let t = e.error, n = e.reason;
17292
17340
  return typeof t == "string" && typeof n == "string" ? `${t}:${n}` : typeof t == "string" ? t : null;
17293
17341
  }
17294
- function Rx(e) {
17342
+ function Vx(e) {
17295
17343
  return e.length === 0 ? null : `all addresses failed | ${e.map((e) => `${e.address}: ${e.error}`).join(" || ")}`;
17296
17344
  }
17297
- function zx(e) {
17345
+ function Hx(e) {
17298
17346
  if (typeof e != "string") return null;
17299
17347
  let t = e.trim();
17300
17348
  return t.length > 0 ? t : null;
17301
17349
  }
17302
- function Bx(e) {
17350
+ function Ux(e) {
17303
17351
  let t = e?.sync_reset;
17304
17352
  if (!t || typeof t != "object" || Array.isArray(t)) return null;
17305
17353
  let n = t;
17306
17354
  if (!Number.isFinite(n.generation) || typeof n.snapshot_id != "string" || n.snapshot_id.trim().length === 0) return null;
17307
- let r = zx(n.baseline_cursor);
17355
+ let r = Hx(n.baseline_cursor);
17308
17356
  return {
17309
- scope_id: zx(n.scope_id),
17357
+ scope_id: Hx(n.scope_id),
17310
17358
  generation: Number(n.generation),
17311
17359
  snapshot_id: n.snapshot_id.trim(),
17312
17360
  baseline_cursor: r,
17313
- retained_floor_cursor: zx(n.retained_floor_cursor)
17361
+ retained_floor_cursor: Hx(n.retained_floor_cursor)
17314
17362
  };
17315
17363
  }
17316
- function Vx(e) {
17364
+ function Wx(e) {
17317
17365
  return !(!e || e.reset_required !== !1 || !Number.isFinite(e.generation) || typeof e.snapshot_id != "string" || e.snapshot_id.trim().length === 0 || !(e.baseline_cursor == null || typeof e.baseline_cursor == "string") || !(e.retained_floor_cursor == null || typeof e.retained_floor_cursor == "string") || !Array.isArray(e.ops) || !(e.next_cursor == null || typeof e.next_cursor == "string") || !Number.isFinite(e.skipped));
17318
17366
  }
17319
- function Hx(e) {
17367
+ function Gx(e) {
17320
17368
  let t = my(e);
17321
17369
  return {
17322
17370
  local: dy,
@@ -17324,14 +17372,14 @@ function Hx(e) {
17324
17372
  negotiated: hy(dy, t)
17325
17373
  };
17326
17374
  }
17327
- function Ux() {
17375
+ function Kx() {
17328
17376
  return { [uy]: dy };
17329
17377
  }
17330
- function Wx() {
17331
- return Hx("unsupported");
17378
+ function qx() {
17379
+ return Gx("unsupported");
17332
17380
  }
17333
- function Gx(e, t, n) {
17334
- let r = P(e, { schema: H }), i = (/* @__PURE__ */ new Date()).toISOString(), a = n.capabilities ?? Wx();
17381
+ function Jx(e, t, n) {
17382
+ let r = P(e, { schema: H }), i = (/* @__PURE__ */ new Date()).toISOString(), a = n.capabilities ?? qx();
17335
17383
  r.insert(ft).values({
17336
17384
  peer_device_id: t,
17337
17385
  started_at: i,
@@ -17345,7 +17393,7 @@ function Gx(e, t, n) {
17345
17393
  negotiated_sync_capability: a.negotiated
17346
17394
  }).run();
17347
17395
  }
17348
- function Kx(e, t, n, r) {
17396
+ function Yx(e, t, n, r) {
17349
17397
  let i = P(e, { schema: H }), { replicationOps: a } = H, o;
17350
17398
  if (t) {
17351
17399
  let e = t.indexOf("|"), s = e >= 0 ? t.slice(0, e) : t, c = e >= 0 ? t.slice(e + 1) : "";
@@ -17357,8 +17405,8 @@ function Kx(e, t, n, r) {
17357
17405
  let c = `${s.created_at}|${s.op_id}`;
17358
17406
  return [o, c];
17359
17407
  }
17360
- var qx = 8;
17361
- async function Jx(e, t, n, r, i = 0) {
17408
+ var Xx = 8;
17409
+ async function Zx(e, t, n, r, i = 0) {
17362
17410
  if (n.length === 0) return;
17363
17411
  let a = {
17364
17412
  ops: n,
@@ -17372,22 +17420,22 @@ async function Jx(e, t, n, r, i = 0) {
17372
17420
  bodyBytes: o,
17373
17421
  keysDir: r
17374
17422
  }),
17375
- ...Ux()
17423
+ ...Kx()
17376
17424
  },
17377
17425
  body: a,
17378
17426
  bodyBytes: o
17379
17427
  });
17380
17428
  if (s === 200 && c != null) return;
17381
- let l = Lx(c);
17382
- if (s === 413 && n.length > 1 && i < qx && (l === "payload_too_large" || l === "too_many_ops")) {
17429
+ let l = Bx(c);
17430
+ if (s === 413 && n.length > 1 && i < Xx && (l === "payload_too_large" || l === "too_many_ops")) {
17383
17431
  let a = Math.floor(n.length / 2);
17384
- await Jx(e, t, n.slice(0, a), r, i + 1), await Jx(e, t, n.slice(a), r, i + 1);
17432
+ await Zx(e, t, n.slice(0, a), r, i + 1), await Zx(e, t, n.slice(a), r, i + 1);
17385
17433
  return;
17386
17434
  }
17387
17435
  let u = l ? ` (${s}: ${l})` : ` (${s})`;
17388
17436
  throw Error(`peer ops push failed${u}`);
17389
17437
  }
17390
- function Yx(e) {
17438
+ function Qx(e) {
17391
17439
  if (!Array.isArray(e)) return [];
17392
17440
  let t = [];
17393
17441
  for (let n of e) {
@@ -17408,25 +17456,25 @@ function Yx(e) {
17408
17456
  scope_id: typeof a.scope_id == "string" ? a.scope_id : null,
17409
17457
  generation: o,
17410
17458
  snapshot_id: s,
17411
- baseline_cursor: zx(a.baseline_cursor),
17412
- retained_floor_cursor: zx(a.retained_floor_cursor)
17459
+ baseline_cursor: Hx(a.baseline_cursor),
17460
+ retained_floor_cursor: Hx(a.retained_floor_cursor)
17413
17461
  }
17414
17462
  });
17415
17463
  }
17416
17464
  return t;
17417
17465
  }
17418
- function Xx(e, t) {
17466
+ function $x(e, t) {
17419
17467
  return e.prepare("SELECT 1 FROM memory_items WHERE import_key IS NOT NULL AND scope_id = ? LIMIT 1").get(t) !== void 0;
17420
17468
  }
17421
- async function Zx(e, t) {
17422
- let n = Yx(t.statusPayload.authorized_scopes);
17469
+ async function eS(e, t) {
17470
+ let n = Qx(t.statusPayload.authorized_scopes);
17423
17471
  if (n.length === 0) return {
17424
17472
  results: [],
17425
17473
  totalOpsIn: 0
17426
17474
  };
17427
17475
  let r = [], i = 0;
17428
17476
  for (let a of n) {
17429
- let n = await Qx(e, {
17477
+ let n = await tS(e, {
17430
17478
  peerDeviceId: t.peerDeviceId,
17431
17479
  baseUrl: t.baseUrl,
17432
17480
  deviceId: t.deviceId,
@@ -17442,8 +17490,8 @@ async function Zx(e, t) {
17442
17490
  totalOpsIn: i
17443
17491
  };
17444
17492
  }
17445
- async function Qx(e, t) {
17446
- let { peerDeviceId: n, baseUrl: r, deviceId: i, scope: a, keysDir: o, scanner: s, limit: c } = t, l = a.scope_id, [u] = cd(e, n, l), d = Xx(e, l);
17493
+ async function tS(e, t) {
17494
+ let { peerDeviceId: n, baseUrl: r, deviceId: i, scope: a, keysDir: o, scanner: s, limit: c } = t, l = a.scope_id, [u] = cd(e, n, l), d = $x(e, l);
17447
17495
  if (u == null && !d) try {
17448
17496
  let t = {
17449
17497
  scope_id: l,
@@ -17455,9 +17503,9 @@ async function Qx(e, t) {
17455
17503
  reason: "initial_bootstrap"
17456
17504
  }, { items: c } = await By(r, t, i, {
17457
17505
  keysDir: o,
17458
- pageSize: Px
17506
+ pageSize: Lx
17459
17507
  });
17460
- if (Xx(e, l)) return {
17508
+ if ($x(e, l)) return {
17461
17509
  scope_id: l,
17462
17510
  label: a.label,
17463
17511
  ok: !1,
@@ -17512,7 +17560,7 @@ async function Qx(e, t) {
17512
17560
  bodyBytes: Buffer.alloc(0),
17513
17561
  keysDir: o
17514
17562
  }),
17515
- ...Ux()
17563
+ ...Kx()
17516
17564
  } });
17517
17565
  if (f === 409 && p?.reset_required === !0) {
17518
17566
  ud(e, n, l);
@@ -17545,7 +17593,7 @@ async function Qx(e, t) {
17545
17593
  };
17546
17594
  }
17547
17595
  if (f !== 200 || p == null) {
17548
- let e = Lx(p), t = e ? ` (${f}: ${e})` : ` (${f})`;
17596
+ let e = Bx(p), t = e ? ` (${f}: ${e})` : ` (${f})`;
17549
17597
  return {
17550
17598
  scope_id: l,
17551
17599
  label: a.label,
@@ -17556,7 +17604,7 @@ async function Qx(e, t) {
17556
17604
  bootstrapped: !1
17557
17605
  };
17558
17606
  }
17559
- if (!Vx(p)) return {
17607
+ if (!Wx(p)) return {
17560
17608
  scope_id: l,
17561
17609
  label: a.label,
17562
17610
  ok: !1,
@@ -17602,8 +17650,8 @@ async function Qx(e, t) {
17602
17650
  bootstrapped: !1
17603
17651
  };
17604
17652
  }
17605
- let _ = zx(p.next_cursor);
17606
- return Ix(u, _) && ld(e, n, { lastApplied: _ }, l), {
17653
+ let _ = Hx(p.next_cursor);
17654
+ return zx(u, _) && ld(e, n, { lastApplied: _ }, l), {
17607
17655
  scope_id: l,
17608
17656
  label: a.label,
17609
17657
  ok: !0,
@@ -17624,13 +17672,13 @@ async function Qx(e, t) {
17624
17672
  };
17625
17673
  }
17626
17674
  }
17627
- function $x(e) {
17675
+ function nS(e) {
17628
17676
  Hn(e), uf(e, 2e3), df(e, 200);
17629
17677
  }
17630
- async function eS(e, t, n, r) {
17678
+ async function rS(e, t, n, r) {
17631
17679
  Hn(e);
17632
- let i = r?.limit ?? Nx, a = r?.keysDir, o = r?.scanner;
17633
- !o && !Mx && (Mx = !0, process.stderr.write("[codemem] sync apply running without explicit scanner — workspace-level secret rules will not apply to inbound peer content\n"));
17680
+ let i = r?.limit ?? Ix, a = r?.keysDir, o = r?.scanner;
17681
+ !o && !Fx && (Fx = !0, process.stderr.write("[codemem] sync apply running without explicit scanner — workspace-level secret rules will not apply to inbound peer content\n"));
17634
17682
  let s = P(e, { schema: H }).select({ pinned_fingerprint: Y.pinned_fingerprint }).from(Y).where(A(Y.peer_device_id, t)).get()?.pinned_fingerprint ?? "";
17635
17683
  if (!s) return {
17636
17684
  ok: !1,
@@ -17644,7 +17692,7 @@ async function eS(e, t, n, r) {
17644
17692
  [u] = dr(e, { keysDir: a });
17645
17693
  } catch (n) {
17646
17694
  let r = `device identity unavailable: ${n instanceof Error ? n.message.trim() || n.constructor.name : "unknown"}`;
17647
- return Gx(e, t, {
17695
+ return Jx(e, t, {
17648
17696
  ok: !1,
17649
17697
  error: r
17650
17698
  }), {
@@ -17669,15 +17717,15 @@ async function eS(e, t, n, r) {
17669
17717
  bodyBytes: Buffer.alloc(0),
17670
17718
  keysDir: a
17671
17719
  }),
17672
- ...Ux()
17720
+ ...Kx()
17673
17721
  } });
17674
17722
  if (d !== 200 || !f) {
17675
- let e = Lx(f), t = e ? ` (${d}: ${e})` : ` (${d})`;
17723
+ let e = Bx(f), t = e ? ` (${d}: ${e})` : ` (${d})`;
17676
17724
  throw Error(`peer status failed${t}`);
17677
17725
  }
17678
17726
  if (f.fingerprint !== s) throw Error("peer fingerprint mismatch");
17679
- if (p = Hx(f.sync_capability), String(f.protocol_version ?? "") !== Fx) throw Error(`peer protocol mismatch (expected ${Fx}, got ${String(f.protocol_version ?? "missing")})`);
17680
- let m = Bx(f);
17727
+ if (p = Gx(f.sync_capability), String(f.protocol_version ?? "") !== Rx) throw Error(`peer protocol mismatch (expected ${Rx}, got ${String(f.protocol_version ?? "missing")})`);
17728
+ let m = Ux(f);
17681
17729
  if (!m) throw Error("peer status missing sync_reset boundary");
17682
17730
  if (c === null && l === null && Number(e.prepare("SELECT count(*) as n FROM memory_items WHERE import_key IS NOT NULL").get()?.n ?? 0) === 0) try {
17683
17731
  let r = {
@@ -17690,9 +17738,9 @@ async function eS(e, t, n, r) {
17690
17738
  reason: "initial_bootstrap"
17691
17739
  }, { items: s } = await By(n, r, u, {
17692
17740
  keysDir: a,
17693
- pageSize: Px
17741
+ pageSize: Lx
17694
17742
  }), c = Number(e.prepare("SELECT count(*) as n FROM memory_items WHERE import_key IS NOT NULL").get()?.n ?? 0);
17695
- if (c > 0) return Gx(e, t, {
17743
+ if (c > 0) return Jx(e, t, {
17696
17744
  ok: !1,
17697
17745
  error: "needs_attention:shared_memories_appeared_during_bootstrap",
17698
17746
  capabilities: p
@@ -17706,7 +17754,7 @@ async function eS(e, t, n, r) {
17706
17754
  };
17707
17755
  let l = qy(e, t, s, r, o);
17708
17756
  if (!l.ok) throw Error("initial bootstrap apply failed");
17709
- let d = p?.negotiated === "scoped" ? await Zx(e, {
17757
+ let d = p?.negotiated === "scoped" ? await eS(e, {
17710
17758
  peerDeviceId: t,
17711
17759
  baseUrl: n,
17712
17760
  deviceId: u,
@@ -17718,7 +17766,7 @@ async function eS(e, t, n, r) {
17718
17766
  results: [],
17719
17767
  totalOpsIn: 0
17720
17768
  }, h = d.results.every((e) => e.ok);
17721
- return _x(e, t, n), Gx(e, t, {
17769
+ return bx(e, t, n), Jx(e, t, {
17722
17770
  ok: h,
17723
17771
  opsIn: l.applied + d.totalOpsIn,
17724
17772
  opsOut: 0,
@@ -17751,7 +17799,7 @@ async function eS(e, t, n, r) {
17751
17799
  bodyBytes: Buffer.alloc(0),
17752
17800
  keysDir: a
17753
17801
  }),
17754
- ...Ux()
17802
+ ...Kx()
17755
17803
  } });
17756
17804
  if (_ === 409 && v?.reset_required === !0) {
17757
17805
  let r = xd(e), i = {
@@ -17763,7 +17811,7 @@ async function eS(e, t, n, r) {
17763
17811
  baseline_cursor: typeof v.baseline_cursor == "string" && v.baseline_cursor.trim() ? v.baseline_cursor.trim() : null,
17764
17812
  retained_floor_cursor: typeof v.retained_floor_cursor == "string" && v.retained_floor_cursor.trim() ? v.retained_floor_cursor.trim() : null
17765
17813
  };
17766
- if (r.dirty) return Gx(e, t, {
17814
+ if (r.dirty) return Jx(e, t, {
17767
17815
  ok: !1,
17768
17816
  error: `needs_attention:local_unsynced_shared_memory:${r.count}`,
17769
17817
  capabilities: p
@@ -17778,7 +17826,7 @@ async function eS(e, t, n, r) {
17778
17826
  };
17779
17827
  try {
17780
17828
  let { items: r } = await By(n, i, u, { keysDir: a }), s = xd(e);
17781
- if (s.dirty) return Gx(e, t, {
17829
+ if (s.dirty) return Jx(e, t, {
17782
17830
  ok: !1,
17783
17831
  error: `needs_attention:local_unsynced_shared_memory:${s.count}`,
17784
17832
  capabilities: p
@@ -17793,7 +17841,7 @@ async function eS(e, t, n, r) {
17793
17841
  };
17794
17842
  let c = qy(e, t, r, i, o);
17795
17843
  if (!c.ok) throw Error("bootstrap apply failed");
17796
- return _x(e, t, n), Gx(e, t, {
17844
+ return bx(e, t, n), Jx(e, t, {
17797
17845
  ok: !0,
17798
17846
  opsIn: c.applied,
17799
17847
  opsOut: 0,
@@ -17807,7 +17855,7 @@ async function eS(e, t, n, r) {
17807
17855
  };
17808
17856
  } catch (r) {
17809
17857
  let a = r instanceof Error ? r.message : String(r);
17810
- return Gx(e, t, {
17858
+ return Jx(e, t, {
17811
17859
  ok: !1,
17812
17860
  error: `bootstrap_failed:${a}`,
17813
17861
  capabilities: p
@@ -17823,10 +17871,10 @@ async function eS(e, t, n, r) {
17823
17871
  }
17824
17872
  }
17825
17873
  if (_ !== 200 || v == null) {
17826
- let e = Lx(v), t = e ? ` (${_}: ${e})` : ` (${_})`;
17874
+ let e = Bx(v), t = e ? ` (${_}: ${e})` : ` (${_})`;
17827
17875
  throw Error(`peer ops fetch failed${t}`);
17828
17876
  }
17829
- if (!Vx(v)) throw Error("invalid ops response");
17877
+ if (!Wx(v)) throw Error("invalid ops response");
17830
17878
  let y = fd(v), b = y.find((e) => e.device_id !== t || e.clock_device_id !== t);
17831
17879
  if (b) throw Error(`inbound op device mismatch:${b.op_id}`);
17832
17880
  let x = p?.negotiated === "unsupported" ? {
@@ -17846,16 +17894,16 @@ async function eS(e, t, n, r) {
17846
17894
  throw Error(`vector catch-up queue failed: ${t instanceof Error ? t.message : String(t)}; fallback failed: ${e}`);
17847
17895
  }
17848
17896
  }
17849
- let C = zx(v.next_cursor);
17850
- Ix(c, C) && (ld(e, t, { lastApplied: C }), c = C);
17851
- let [w, ee] = Kx(e, l, u, i), [te, ne, re] = Kd(e, w, t, { localDeviceId: u }), ie = re?.skipped_count ?? 0, T = `${n}/v1/ops`;
17897
+ let C = Hx(v.next_cursor);
17898
+ zx(c, C) && (ld(e, t, { lastApplied: C }), c = C);
17899
+ let [w, ee] = Yx(e, l, u, i), [te, ne, re] = Kd(e, w, t, { localDeviceId: u }), ie = re?.skipped_count ?? 0, T = `${n}/v1/ops`;
17852
17900
  if (te.length > 0) {
17853
- let e = id(te, jx);
17854
- for (let t of e) await Jx(T, u, t, a);
17901
+ let e = id(te, Px);
17902
+ for (let t of e) await Zx(T, u, t, a);
17855
17903
  }
17856
17904
  let ae = ne ?? ee;
17857
- ae && Ix(l, ae) && (ld(e, t, { lastAcked: ae }), l = ae);
17858
- let oe = p?.negotiated === "scoped" ? await Zx(e, {
17905
+ ae && zx(l, ae) && (ld(e, t, { lastAcked: ae }), l = ae);
17906
+ let oe = p?.negotiated === "scoped" ? await eS(e, {
17859
17907
  peerDeviceId: t,
17860
17908
  baseUrl: n,
17861
17909
  deviceId: u,
@@ -17867,7 +17915,7 @@ async function eS(e, t, n, r) {
17867
17915
  results: [],
17868
17916
  totalOpsIn: 0
17869
17917
  }, E = oe.results.every((e) => e.ok);
17870
- return _x(e, t, n), Gx(e, t, {
17918
+ return bx(e, t, n), Jx(e, t, {
17871
17919
  ok: E,
17872
17920
  opsIn: S.applied + oe.totalOpsIn,
17873
17921
  opsOut: te.length,
@@ -17892,8 +17940,8 @@ async function eS(e, t, n, r) {
17892
17940
  }
17893
17941
  }
17894
17942
  }
17895
- let m = Rx(d);
17896
- return f || (m = "no dialable peer addresses"), m ||= "sync failed without diagnostic detail", Gx(e, t, {
17943
+ let m = Vx(d);
17944
+ return f || (m = "no dialable peer addresses"), m ||= "sync failed without diagnostic detail", Jx(e, t, {
17897
17945
  ok: !1,
17898
17946
  error: m,
17899
17947
  capabilities: p
@@ -17905,15 +17953,15 @@ async function eS(e, t, n, r) {
17905
17953
  addressErrors: d
17906
17954
  };
17907
17955
  }
17908
- async function tS(e, t, n) {
17956
+ async function iS(e, t, n) {
17909
17957
  let r = P(e, { schema: H }).select({ addresses_json: Y.addresses_json }).from(Y).where(A(Y.peer_device_id, t)).get(), i = [];
17910
17958
  if (r?.addresses_json) try {
17911
17959
  let e = JSON.parse(r.addresses_json);
17912
17960
  Array.isArray(e) && (i = e.filter((e) => typeof e == "string"));
17913
17961
  } catch {}
17914
- return eS(e, t, i, n);
17962
+ return rS(e, t, i, n);
17915
17963
  }
17916
- var nS = [
17964
+ var aS = [
17917
17965
  "no route to host",
17918
17966
  "connection refused",
17919
17967
  "network is unreachable",
@@ -17924,33 +17972,33 @@ var nS = [
17924
17972
  "errno 61",
17925
17973
  "errno 60",
17926
17974
  "errno 111"
17927
- ], rS = 120, iS = 1800;
17928
- function aS(e) {
17975
+ ], oS = 120, sS = 1800;
17976
+ function cS(e) {
17929
17977
  if (!e) return !1;
17930
17978
  let t = e.toLowerCase();
17931
- return nS.some((e) => t.includes(e));
17979
+ return aS.some((e) => t.includes(e));
17932
17980
  }
17933
- function oS(e, t, n = 10) {
17981
+ function lS(e, t, n = 10) {
17934
17982
  let r = P(e, { schema: H }).select({
17935
17983
  ok: ft.ok,
17936
17984
  error: ft.error
17937
17985
  }).from(ft).where(A(ft.peer_device_id, t)).orderBy(le(ft.started_at)).limit(n).all(), i = 0;
17938
17986
  for (let e of r) {
17939
17987
  if (e.ok) break;
17940
- if (aS(e.error)) i++;
17988
+ if (cS(e.error)) i++;
17941
17989
  else break;
17942
17990
  }
17943
17991
  return i;
17944
17992
  }
17945
- function sS(e) {
17993
+ function uS(e) {
17946
17994
  if (e <= 1) return 0;
17947
17995
  let t = Math.min(e - 1, 8);
17948
- return Math.min(rS * 2 ** (t - 1), iS) * (.5 + Math.random() * .5);
17996
+ return Math.min(oS * 2 ** (t - 1), sS) * (.5 + Math.random() * .5);
17949
17997
  }
17950
- function cS(e, t) {
17951
- let n = oS(e, t);
17998
+ function dS(e, t) {
17999
+ let n = lS(e, t);
17952
18000
  if (n < 2) return !1;
17953
- let r = sS(n);
18001
+ let r = uS(n);
17954
18002
  if (r <= 0) return !1;
17955
18003
  let i = P(e, { schema: H }).select({ started_at: ft.started_at }).from(ft).where(A(ft.peer_device_id, t)).orderBy(le(ft.started_at)).limit(1).get();
17956
18004
  if (!i?.started_at) return !1;
@@ -17963,13 +18011,13 @@ function cS(e, t) {
17963
18011
  }
17964
18012
  //#endregion
17965
18013
  //#region src/sync-daemon.ts
17966
- function lS(e) {
18014
+ function fS(e) {
17967
18015
  return e?.trim() || process.env.CODEMEM_KEYS_DIR?.trim() || void 0;
17968
18016
  }
17969
- function uS(e, t, n) {
18017
+ function pS(e, t, n) {
17970
18018
  return e.prepare(`PRAGMA table_info(${t})`).all().some((e) => e.name === n);
17971
18019
  }
17972
- function dS(e) {
18020
+ function mS(e) {
17973
18021
  let t = P(e, { schema: H }), n = (/* @__PURE__ */ new Date()).toISOString();
17974
18022
  t.insert(mt).values({
17975
18023
  id: 1,
@@ -17983,7 +18031,7 @@ function dS(e) {
17983
18031
  }
17984
18032
  }).run();
17985
18033
  }
17986
- function fS(e, t, n) {
18034
+ function hS(e, t, n) {
17987
18035
  let r = P(e, { schema: H }), i = (/* @__PURE__ */ new Date()).toISOString();
17988
18036
  r.insert(mt).values({
17989
18037
  id: 1,
@@ -17999,11 +18047,11 @@ function fS(e, t, n) {
17999
18047
  }
18000
18048
  }).run();
18001
18049
  }
18002
- function pS(e) {
18050
+ function gS(e) {
18003
18051
  let t = P(e, { schema: H }).select({ phase: mt.phase }).from(mt).where(A(mt.id, 1)).get()?.phase;
18004
18052
  return t === "needs_attention" ? t : null;
18005
18053
  }
18006
- function mS(e, t) {
18054
+ function _S(e, t) {
18007
18055
  P(e, { schema: H }).insert(mt).values({
18008
18056
  id: 1,
18009
18057
  phase: t
@@ -18012,18 +18060,18 @@ function mS(e, t) {
18012
18060
  set: { phase: t }
18013
18061
  }).run();
18014
18062
  }
18015
- async function hS(e, t, n) {
18063
+ async function vS(e, t, n) {
18016
18064
  let r = Vl();
18017
18065
  return Hl(r) ? (await Wl({
18018
18066
  db: e,
18019
18067
  dbPath: t
18020
18068
  }, r, { keysDir: n }), await Au(e, r, { keysDir: n }), !0) : !1;
18021
18069
  }
18022
- async function gS(e, t, n, r) {
18023
- let i = uS(e, "sync_peers", "pinned_fingerprint"), a = e.prepare(i ? "SELECT peer_device_id, pinned_fingerprint FROM sync_peers" : "SELECT peer_device_id, NULL AS pinned_fingerprint FROM sync_peers").all();
18070
+ async function yS(e, t, n, r) {
18071
+ let i = pS(e, "sync_peers", "pinned_fingerprint"), a = e.prepare(i ? "SELECT peer_device_id, pinned_fingerprint FROM sync_peers" : "SELECT peer_device_id, NULL AS pinned_fingerprint FROM sync_peers").all();
18024
18072
  if (a.length === 0) return [];
18025
18073
  let o = Vl().syncOpsLimit;
18026
- $x(e);
18074
+ nS(e);
18027
18075
  let s = [];
18028
18076
  for (let i of a) {
18029
18077
  let a = i.peer_device_id, c = String(i.pinned_fingerprint ?? "").trim(), l = c ? `${a}:${c}` : "";
@@ -18035,7 +18083,7 @@ async function gS(e, t, n, r) {
18035
18083
  });
18036
18084
  continue;
18037
18085
  }
18038
- if (cS(e, a)) {
18086
+ if (dS(e, a)) {
18039
18087
  s.push({
18040
18088
  ok: !1,
18041
18089
  skipped: !0,
@@ -18043,7 +18091,7 @@ async function gS(e, t, n, r) {
18043
18091
  });
18044
18092
  continue;
18045
18093
  }
18046
- let u = await tS(e, a, {
18094
+ let u = await iS(e, a, {
18047
18095
  keysDir: t,
18048
18096
  limit: o,
18049
18097
  scanner: r
@@ -18057,13 +18105,13 @@ async function gS(e, t, n, r) {
18057
18105
  }
18058
18106
  return s;
18059
18107
  }
18060
- async function _S(e) {
18061
- let t = e?.intervalS ?? 120, n = Dn(e?.dbPath), r = lS(e?.keysDir), i = e?.signal, a = e?.onPhaseChange, o = e?.scanner;
18108
+ async function bS(e) {
18109
+ let t = e?.intervalS ?? 120, n = Dn(e?.dbPath), r = fS(e?.keysDir), i = e?.signal, a = e?.onPhaseChange, o = e?.scanner;
18062
18110
  a?.("starting");
18063
18111
  let s = Mn(n), c = null;
18064
18112
  try {
18065
18113
  let [t] = dr(s, { keysDir: r });
18066
- Sx() && e?.port && (c = Ox(t, e.port));
18114
+ Tx() && e?.port && (c = jx(t, e.port));
18067
18115
  } finally {
18068
18116
  s.close();
18069
18117
  }
@@ -18073,7 +18121,7 @@ async function _S(e) {
18073
18121
  }
18074
18122
  return new Promise((e) => {
18075
18123
  let s = !1, l = !1, u = () => {
18076
- s || (s = !0, vS(n, r, o).finally(() => {
18124
+ s || (s = !0, xS(n, r, o).finally(() => {
18077
18125
  s = !1, l || (l = !0, a?.("running"));
18078
18126
  }));
18079
18127
  }, d = setInterval(u, t * 1e3);
@@ -18090,38 +18138,38 @@ async function _S(e) {
18090
18138
  }
18091
18139
  });
18092
18140
  }
18093
- async function vS(e, t, n) {
18094
- let r = lS(t), i = Mn(e);
18141
+ async function xS(e, t, n) {
18142
+ let r = fS(t), i = Mn(e);
18095
18143
  try {
18096
18144
  Hn(i);
18097
18145
  try {
18098
- await hS(i, e, r);
18146
+ await vS(i, e, r);
18099
18147
  } catch {}
18100
- (await gS(i, r, await Yl(i, e, r), n)).some((e) => !e.ok && e.error?.includes("needs_attention")) ? mS(i, "needs_attention") : dS(i);
18148
+ (await yS(i, r, await Yl(i, e, r), n)).some((e) => !e.ok && e.error?.includes("needs_attention")) ? _S(i, "needs_attention") : mS(i);
18101
18149
  } catch (e) {
18102
- fS(i, e instanceof Error ? e.message : String(e), e instanceof Error ? e.stack ?? "" : "");
18150
+ hS(i, e instanceof Error ? e.message : String(e), e instanceof Error ? e.stack ?? "" : "");
18103
18151
  } finally {
18104
18152
  i.close();
18105
18153
  }
18106
18154
  }
18107
18155
  //#endregion
18108
18156
  //#region src/sync-retention-runner.ts
18109
- function yS(e) {
18157
+ function SS(e) {
18110
18158
  let t = String(e ?? "").trim();
18111
18159
  return t.length > 0 ? t : Lu;
18112
18160
  }
18113
- function bS(e) {
18161
+ function CS(e) {
18114
18162
  e.exec("\n CREATE TABLE IF NOT EXISTS sync_retention_state (\n id INTEGER PRIMARY KEY,\n last_run_at TEXT,\n last_duration_ms INTEGER,\n last_deleted_ops INTEGER NOT NULL DEFAULT 0,\n last_estimated_bytes_before INTEGER,\n last_estimated_bytes_after INTEGER,\n retained_floor_cursor TEXT,\n last_error TEXT,\n last_error_at TEXT\n );\n CREATE TABLE IF NOT EXISTS sync_retention_state_v2 (\n scope_id TEXT PRIMARY KEY NOT NULL,\n last_run_at TEXT,\n last_duration_ms INTEGER,\n last_deleted_ops INTEGER NOT NULL DEFAULT 0,\n last_estimated_bytes_before INTEGER,\n last_estimated_bytes_after INTEGER,\n retained_floor_cursor TEXT,\n last_error TEXT,\n last_error_at TEXT\n )\n ");
18115
18163
  }
18116
- function xS(e) {
18164
+ function wS(e) {
18117
18165
  let t = e.prepare("SELECT scope_id FROM (\n SELECT COALESCE(NULLIF(TRIM(scope_id), ''), ?) AS scope_id FROM replication_ops\n UNION\n SELECT COALESCE(NULLIF(TRIM(scope_id), ''), ?) AS scope_id FROM sync_reset_state_v2\n UNION\n SELECT COALESCE(NULLIF(TRIM(scope_id), ''), ?) AS scope_id FROM sync_retention_state_v2\n )\n ORDER BY CASE WHEN scope_id = ? THEN 0 ELSE 1 END, scope_id").all(Lu, Lu, Lu, Lu), n = new Set([Lu]);
18118
18166
  for (let e of t) {
18119
- let t = yS(e.scope_id);
18167
+ let t = SS(e.scope_id);
18120
18168
  n.add(t);
18121
18169
  }
18122
18170
  return Array.from(n);
18123
18171
  }
18124
- function SS(e, t, n, r) {
18172
+ function TS(e, t, n, r) {
18125
18173
  e.insert(vt).values({
18126
18174
  scope_id: t,
18127
18175
  ...n
@@ -18136,7 +18184,7 @@ function SS(e, t, n, r) {
18136
18184
  set: n
18137
18185
  }).run();
18138
18186
  }
18139
- function CS(e, t, n, r, i) {
18187
+ function ES(e, t, n, r, i) {
18140
18188
  let a = i === Lu;
18141
18189
  try {
18142
18190
  let o = Dd(e, i), s = Cd(e, {
@@ -18148,7 +18196,7 @@ function CS(e, t, n, r, i) {
18148
18196
  maxPasses: n.maxCatchUpPasses,
18149
18197
  signal: n.signal
18150
18198
  });
18151
- SS(t, i, {
18199
+ TS(t, i, {
18152
18200
  last_run_at: r,
18153
18201
  last_duration_ms: Date.now() - Date.parse(r),
18154
18202
  last_deleted_ops: s.totalDeleted,
@@ -18159,7 +18207,7 @@ function CS(e, t, n, r, i) {
18159
18207
  last_error_at: null
18160
18208
  }, a);
18161
18209
  } catch (e) {
18162
- SS(t, i, {
18210
+ TS(t, i, {
18163
18211
  last_run_at: r,
18164
18212
  last_duration_ms: Date.now() - Date.parse(r),
18165
18213
  last_deleted_ops: 0,
@@ -18171,13 +18219,13 @@ function CS(e, t, n, r, i) {
18171
18219
  }, a);
18172
18220
  }
18173
18221
  }
18174
- async function wS(e, t) {
18222
+ async function DS(e, t) {
18175
18223
  if (!t.syncRetentionEnabled) return;
18176
- bS(e);
18177
- let n = P(e, { schema: H }), r = (/* @__PURE__ */ new Date()).toISOString(), i = t.scopeId === void 0 ? xS(e) : [yS(t.scopeId)];
18178
- for (let a of i) CS(e, n, t, r, a);
18224
+ CS(e);
18225
+ let n = P(e, { schema: H }), r = (/* @__PURE__ */ new Date()).toISOString(), i = t.scopeId === void 0 ? wS(e) : [SS(t.scopeId)];
18226
+ for (let a of i) ES(e, n, t, r, a);
18179
18227
  }
18180
- var TS = class {
18228
+ var OS = class {
18181
18229
  dbPath;
18182
18230
  signal;
18183
18231
  active = !1;
@@ -18205,7 +18253,7 @@ var TS = class {
18205
18253
  if (!this.active || this.signal?.aborted) return;
18206
18254
  let e = Vl(Rt()), t = Mn(this.dbPath);
18207
18255
  try {
18208
- await wS(t, {
18256
+ await DS(t, {
18209
18257
  ...e,
18210
18258
  signal: this.signal
18211
18259
  });
@@ -18213,8 +18261,8 @@ var TS = class {
18213
18261
  t.close();
18214
18262
  }
18215
18263
  }
18216
- }, ES = "scope_id";
18217
- function DS(e, t, n) {
18264
+ }, kS = "scope_id";
18265
+ function AS(e, t, n) {
18218
18266
  if (!t) return {
18219
18267
  ok: !0,
18220
18268
  mode: "legacy",
@@ -18235,7 +18283,7 @@ function DS(e, t, n) {
18235
18283
  ok: !1,
18236
18284
  reason: "missing_scope"
18237
18285
  };
18238
- let c = OS(Mu(a, {
18286
+ let c = jS(Mu(a, {
18239
18287
  deviceId: o,
18240
18288
  scopeId: r
18241
18289
  }));
@@ -18243,7 +18291,7 @@ function DS(e, t, n) {
18243
18291
  ok: !1,
18244
18292
  reason: c
18245
18293
  };
18246
- let l = OS(Mu(a, {
18294
+ let l = jS(Mu(a, {
18247
18295
  deviceId: s,
18248
18296
  scopeId: r
18249
18297
  }));
@@ -18256,7 +18304,7 @@ function DS(e, t, n) {
18256
18304
  scope_id: r
18257
18305
  };
18258
18306
  }
18259
- function OS(e) {
18307
+ function jS(e) {
18260
18308
  if (e.authorized) return null;
18261
18309
  switch (e.state) {
18262
18310
  case "stale_epoch": return "stale_epoch";
@@ -18265,22 +18313,22 @@ function OS(e) {
18265
18313
  default: return "missing_scope";
18266
18314
  }
18267
18315
  }
18268
- function kS(e, t) {
18316
+ function MS(e, t) {
18269
18317
  return {
18270
18318
  ...e,
18271
18319
  scope_id: t
18272
18320
  };
18273
18321
  }
18274
- function AS(e, t, n, r) {
18322
+ function NS(e, t, n, r) {
18275
18323
  return {
18276
18324
  error: "reset_required",
18277
18325
  reset_required: !0,
18278
18326
  sync_capability: n,
18279
18327
  reason: t,
18280
- ...kS(e, r ?? null)
18328
+ ...MS(e, r ?? null)
18281
18329
  };
18282
18330
  }
18283
- function jS(e, t) {
18331
+ function PS(e, t) {
18284
18332
  let n = t.localDeviceId.trim(), r = t.peerDeviceId.trim();
18285
18333
  if (!n || !r || n === r) return [];
18286
18334
  let i = P(e, { schema: H }).select({
@@ -18313,9 +18361,9 @@ function jS(e, t) {
18313
18361
  }
18314
18362
  return a.sort((e, t) => e.scope_id.localeCompare(t.scope_id)), a;
18315
18363
  }
18316
- function MS(e, t) {
18364
+ function FS(e, t) {
18317
18365
  let n = t.localDeviceId?.trim() ?? "", r = t.peerDeviceId.trim();
18318
- return !n || !r ? [] : jS(e, {
18366
+ return !n || !r ? [] : PS(e, {
18319
18367
  localDeviceId: n,
18320
18368
  peerDeviceId: r
18321
18369
  }).map((t) => {
@@ -18333,14 +18381,14 @@ function MS(e, t) {
18333
18381
  }
18334
18382
  //#endregion
18335
18383
  //#region src/test-utils.ts
18336
- function NS(e) {
18384
+ function IS(e) {
18337
18385
  hn(e);
18338
18386
  }
18339
- function PS(e) {
18387
+ function LS(e) {
18340
18388
  let t = (/* @__PURE__ */ new Date()).toISOString(), n = e.prepare("INSERT INTO sessions(started_at, cwd, project, user, tool_version) VALUES (?, ?, ?, ?, ?)").run(t, "/tmp/test", "test-project", "test-user", "test");
18341
18389
  return Number(n.lastInsertRowid);
18342
18390
  }
18343
- function FS(e, t = "local") {
18391
+ function RS(e, t = "local") {
18344
18392
  let n = "2026-04-01T00:00:00.000Z", r = "fixture-work-authorized", i = "fixture-oss-hidden", a = "mixedscopeleak";
18345
18393
  e.prepare("INSERT OR IGNORE INTO sync_device(device_id, public_key, fingerprint, created_at) VALUES (?, ?, ?, ?)").run(t, "fixture-public-key", "fixture-fingerprint", n), e.prepare("INSERT OR REPLACE INTO replication_scopes(\n scope_id, label, kind, authority_type, coordinator_id, group_id,\n membership_epoch, status, created_at, updated_at\n ) VALUES (?, ?, 'team', 'coordinator', 'fixture-coordinator', 'fixture-group', 0, 'active', ?, ?)").run(r, "Authorized work fixture", n, n), e.prepare("INSERT OR REPLACE INTO replication_scopes(\n scope_id, label, kind, authority_type, coordinator_id, group_id,\n membership_epoch, status, created_at, updated_at\n ) VALUES (?, ?, 'team', 'coordinator', 'fixture-coordinator', 'fixture-group', 0, 'active', ?, ?)").run(i, "Hidden OSS fixture", n, n), e.prepare("INSERT OR REPLACE INTO scope_memberships(\n scope_id, device_id, role, status, membership_epoch,\n coordinator_id, group_id, updated_at\n ) VALUES (?, ?, 'member', 'active', 0, 'fixture-coordinator', 'fixture-group', ?)").run(r, t, n);
18346
18394
  let o = e.prepare("INSERT INTO sessions(started_at, cwd, project, user, tool_version, metadata_json, import_key)\n VALUES (?, '/tmp/mixed-domain-fixture', 'mixed-domain-fixture', 'test-user', 'test', '{}', 'fixture-session')").run(n), s = Number(o.lastInsertRowid), c = (t) => {
@@ -18389,8 +18437,8 @@ function FS(e, t = "local") {
18389
18437
  }
18390
18438
  //#endregion
18391
18439
  //#region src/index.ts
18392
- var IS = "0.33.0-alpha.2";
18440
+ var zS = "0.33.0";
18393
18441
  //#endregion
18394
- export { Oe as Api, Xe as BetterSqliteCoordinatorStore, Ft as CODEMEM_CONFIG_ENV_OVERRIDES, Uh as DEDUP_KEY_BACKFILL_JOB, z as DEFAULT_COORDINATOR_DB_PATH, En as DEFAULT_DB_PATH, tu as DEFAULT_SCOPE_MEMBERSHIP_CACHE_MAX_AGE_MS, fx as DEFAULT_SERVICE_TYPE, Lu as DEFAULT_SYNC_SCOPE_ID, o as DEFAULT_TIME_WINDOW_S, qh as DedupKeyBackfillRunner, si as INJECTION_EVAL_SCENARIO_PACKS, Wv as LEGACY_SHARED_REVIEW_SCOPE_ID, Ei as LOCAL_DEFAULT_SCOPE_ID, dy as LOCAL_SYNC_CAPABILITY, o_ as LOW_SIGNAL_TOOLS, Sr as MAPPABLE_CLAUDE_HOOK_EVENTS, Cn as MIN_COMPATIBLE_SCHEMA, ke as MUTATING_TOOL_NAMES, If as MemoryStore, Ip as ObserverAuthAdapter, cm as ObserverAuthError, Nm as ObserverClient, Ib as REF_BACKFILL_JOB, Ig as RICH_TIER_DEFAULTS, Fb as RawEventSweeper, Hb as RefBackfillRunner, Sn as SCHEMA_VERSION, Gv as SCOPE_BACKFILL_JOB, n as SCOPE_MEMBERSHIP_REVOCATION_LIMITATION, Ub as SESSION_CONTEXT_BACKFILL_JOB, fr as SIGNATURE_VERSION, Fg as SIMPLE_TIER_DEFAULTS, rx as SUMMARY_DEDUP_BACKFILL_JOB, ly as SYNC_CAPABILITIES, uy as SYNC_CAPABILITY_HEADER, ES as SYNC_SCOPE_QUERY_PARAM, sy as ScopeBackfillRunner, nx as SessionContextBackfillRunner, ux as SummaryDedupBackfillRunner, TS as SyncRetentionRunner, P_ as TRIVIAL_REQUESTS, gy as VECTOR_MODEL_MIGRATION_JOB, IS as VERSION, Ry as VectorModelMigrationRunner, es as _resetEmbeddingClient, kS as addSyncScopeToBoundary, Tl as addressDedupeKey, Ox as advertiseMdns, Jm as aiBackfillStructuredContent, Eb as analyzeProjectScopeMappingChangeGuardrails, qy as applyBootstrapSnapshot, mf as applyReplicationOps, zn as assertSchemaReady, gp as backfillMemoryDedupKeys, dp as backfillNarrativeFromBody, df as backfillReplicationOps, ry as backfillScopeIds, tp as backfillTagsText, js as backfillVectors, hn as bootstrapSchema, v_ as budgetToolEvents, _r as buildAuthHeaders, Al as buildBaseUrl, pr as buildCanonicalRequest, Ap as buildCodexHeaders, Yi as buildFilterClauses, Xi as buildFilterClausesWithContext, ig as buildImportKey, zr as buildIngestPayloadFromHook, $c as buildMemoryPack, tl as buildMemoryPackAsync, el as buildMemoryPackTrace, nl as buildMemoryPackTraceAsync, M_ as buildObserverPrompt, Rr as buildRawEventEnvelopeFromHook, Ev as buildSessionContext, U_ as buildTranscript, wd as bulkPruneReplicationOpsByAgeCutoff, mi as canonicalMemoryKind, Mi as canonicalWorkspaceIdentity, id as chunkOpsBySize, Qo as chunkText, Jv as classifyLegacyMemoryScope, yv as cleanOrphanSessions, yr as cleanupNonces, ga as clearMemoryRefs, pd as clockTuple, Kf as compareMemoryRoleReports, Yr as completeMaintenanceJob, Mn as connect, Ye as connectCoordinator, oS as consecutiveConnectivityFailures, mh as coordinatorArchiveGroupAction, fh as coordinatorCreateGroupAction, kh as coordinatorCreateInviteAction, vh as coordinatorCreateScopeAction, Eh as coordinatorDisableDeviceAction, Dh as coordinatorEnableDeviceAction, Hl as coordinatorEnabled, Ch as coordinatorEnrollDeviceAction, xh as coordinatorGrantScopeMembershipAction, Ah as coordinatorImportInviteAction, Nh as coordinatorListBootstrapGrantsAction, wh as coordinatorListDevicesAction, gh as coordinatorListGroupsAction, jh as coordinatorListJoinRequestsAction, bh as coordinatorListScopeMembershipsAction, _h as coordinatorListScopesAction, Oh as coordinatorRemoveDeviceAction, Th as coordinatorRenameDeviceAction, ph as coordinatorRenameGroupAction, Mh as coordinatorReviewJoinRequestAction, Ph as coordinatorRevokeBootstrapGrantAction, Sh as coordinatorRevokeScopeMembershipAction, $l as coordinatorStatusSnapshot, hh as coordinatorUnarchiveGroupAction, yh as coordinatorUpdateScopeAction, br as createBetterSqliteCoordinatorApp, c as createCoordinatorApp, Zl as createCoordinatorReciprocalApproval, Ix as cursorAdvances, cp as deactivateLowSignalMemories, sp as deactivateLowSignalObservations, qg as decideExtractionReplayTier, s as decodeInvitePayload, lp as dedupNearDuplicateMemories, Ko as dedupeOrderedIds, Fh as defaultSpaceScopeIdForGroup, Hh as deleteCoordinatorGroupPreference, jb as deleteProjectScopeSettingsMapping, H_ as deriveRequest, Iu as deriveTags, kx as discoverPeersViaMdns, rs as embedTexts, t as encodeInvitePayload, dr as ensureDeviceIdentity, Zr as ensureMaintenanceJobsSchema, yn as ensureSchemaBootstrapped, Xv as ensureScopeBackfillScopes, su as ensureScopeMembershipCacheStateTable, Hs as estimateTokens, Ng as evaluateSessionExtractionItems, d_ as eventToToolEvent, qa as expandQuery, Xo as explain, e as explainScopeMembershipRevocation, pg as exportMemories, p_ as extractAdapterEvent, Ae as extractApplyPatchPaths, W_ as extractAssistantMessages, G_ as extractAssistantUsage, r as extractInvitePayload, up as extractNarrativeFromBody, Tp as extractOAuthAccess, Op as extractOAuthAccountId, kp as extractOAuthExpires, K_ as extractPrompts, Ep as extractProviderApiKey, fd as extractReplicationOps, f_ as extractToolEvents, Xr as failMaintenanceJob, By as fetchAllSnapshotPages, Yl as fetchCoordinatorStalePeers, Fu as fileTags, qd as filterReplicationOpsForSync, Kd as filterReplicationOpsForSyncWithStatus, ba as findByConcept, ya as findByFile, i as fingerprintPublicKey, V_ as firstSentence, Ov as flushRawEvents, wl as formatHostPort, Un as fromJson, Wn as fromJsonStrict, sr as generateKeypair, Mu as getCachedScopeAuthorization, Lt as getCodememConfigPath, Ht as getCodememEnvOverrides, zh as getCoordinatorGroupPreference, ns as getEmbeddingClient, Tg as getExtractionBenchmarkProfile, oi as getInjectionEvalScenarioByPrompt, ci as getInjectionEvalScenarioPack, li as getInjectionEvalScenarioPrompts, Q as getMaintenanceJob, Gf as getMemoryRoleReport, Wt as getOpenCodeProviderConfig, sn as getProviderApiKey, an as getProviderBaseUrl, on as getProviderHeaders, rn as getProviderOptions, ri as getRawEventRelinkPlan, ni as getRawEventRelinkReport, qf as getRawEventStatus, Yf as getReliabilityMetrics, cd as getReplicationCursor, Rn as getSchemaVersion, Ts as getSemanticIndexDiagnostics, Pg as getSessionExtractionEval, Mg as getSessionExtractionEvalScenario, di as getSummaryMetadata, pS as getSyncDaemonPhase, $u as getSyncResetState, At as getWorkspaceCodememConfigPath, jt as getWorkspaceScopedCodememConfigPath, av as hasMeaningfulObservation, Wh as hasPendingDedupKeyBackfill, Rb as hasPendingRefBackfill, ey as hasPendingScopeBackfill, $b as hasPendingSessionContextBackfill, ax as hasPendingSummaryDedupBackfill, xd as hasUnsyncedSharedMemoryChanges, Zo as hashText, Cg as importMemories, _v as ingest, bv as ingestMain, ii as initDatabase, NS as initTestSchema, PS as insertTestSession, l as inviteLink, aS as isConnectivityError, Ln as isEmbeddingDisabled, s_ as isInternalMemoryTool, ip as isLowSignalObservation, md as isNewerClock, py as isScopedSyncCapability, $g as isSensitiveFieldName, fi as isSummaryLikeMemory, B_ as isTrivialRequest, Ya as kindBonus, jS as listAuthorizedScopesForPeer, ju as listCachedScopesForDevice, Jt as listConfiguredOpenCodeProviders, Bh as listCoordinatorGroupPreferences, eu as listCoordinatorJoinRequests, Xl as listCoordinatorReciprocalApprovals, Gt as listCustomProviders, Eg as listExtractionBenchmarkProfiles, sf as listInboundScopeRejections, Kr as listMaintenanceJobs, Yt as listObserverProviderOptions, MS as listPerPeerScopeSyncState, Db as listProjectScopeCandidates, Ob as listProjectScopeInventory, xb as listProjectScopeSettingsMappings, bb as listSharingDomainSettingsScopes, bd as loadMemorySnapshotPageForPeer, sm as loadObserverConfig, Dt as loadOpenCodeConfig, Sp as loadOpenCodeOAuthCache, mx as loadPeerAddresses, rr as loadPrivateKey, er as loadPrivateKeyKeychain, nr as loadPublicKey, yd as loadReplicationOpsForPeer, vd as loadReplicationOpsSince, In as loadSqliteVec, Gl as lookupCoordinatorPeers, Ir as mapClaudeHookPayload, Ax as mdnsAddressesForPeer, Sx as mdnsEnabled, El as mergeAddresses, ag as mergeSummaryMetadata, jn as migrateLegacyDbPath, uf as migrateLegacyImportKeys, hy as negotiateSyncCapability, J_ as normalizeAdapterEvents, Cl as normalizeAddress, ha as normalizeConcept, q_ as normalizeEventsForSessionContext, rp as normalizeObservation, Dr as normalizeProjectLabel, z_ as normalizeRequestText, my as normalizeSyncCapability, Pu as normalizeTag, c_ as normalizeToolName, iv as parseObserverResponse, wa as parsePositiveMemoryId, Ca as parseStrictInteger, DS as parseSyncScopeRequest, sS as peerBackoffSeconds, Rd as peerCanSyncPrivateOpByPersonalScopeGrant, Fd as personalScopeGrantStatusForPeer, Td as planReplicationOpsAgePrune, _a as populateMemoryRefs, Dp as probeAvailableCredentials, m_ as projectAdapterToolEvent, yi as projectBasename, Si as projectClause, xi as projectColumnClause, Ci as projectMatchesFilter, Sd as pruneReplicationOps, Cd as pruneReplicationOpsUntilCaughtUp, Xf as rawEventsGate, Np as readAuthFile, Rt as readCodememConfigFile, zt as readCodememConfigFileAtPath, Vl as readCoordinatorSyncConfig, mg as readImportPayload, Pt as readWorkspaceCodememConfigFile, kb as reassignProjectScopeInventoryProject, Ja as recencyScore, vr as recordNonce, _x as recordPeerSuccess, hd as recordReplicationOp, gx as recordSyncAttempt, yp as redactText, Au as refreshConfiguredScopeMembershipCache, ku as refreshScopeMembershipCache, Jl as refreshStoredCoordinatorPeerAddresses, Wl as registerCoordinatorPresence, af as rejectInboundScopeFailures, Bp as renderObserverHeaders, Hv as replayBatchExtraction, Uv as replayBatchExtractionWithTierRouting, Ld as replicationOpRequiresPersonalScopeAuthorization, jl as requestJson, zo as rerankResults, Zt as resolveBuiltInProviderDefaultModel, Xt as resolveBuiltInProviderFromModel, Qt as resolveBuiltInProviderModel, It as resolveCodememConfigPath, cn as resolveCustomProviderDefaultModel, $t as resolveCustomProviderFromModel, ln as resolveCustomProviderModel, Dn as resolveDbPath, Ar as resolveHookProject, tr as resolveKeyPaths, Cp as resolveOAuthProvider, en as resolvePlaceholder, Ti as resolveProject, Vi as resolveProjectScope, Jf as retryRawEventFailures, jp as runAuthCommand, Kh as runDedupKeyBackfillPass, Vb as runRefBackfillPass, oy as runScopeBackfillPass, ex as runSessionContextBackfillPass, lx as runSummaryDedupBackfillPass, _S as runSyncDaemon, tS as runSyncPass, Ly as runVectorMigrationPass, n_ as sanitizePayload, a_ as sanitizeToolOutput, nh as scanSecretsRetroactive, H as schema, OS as scopeAuthorizationFailureReason, a as scopeMembershipEpochStatus, Bo as search, FS as seedMixedScopeFixture, px as selectDialAddresses, Ms as semanticSearch, as as serializeFloat32, yx as setPeerLocalActorClaim, vx as setPeerProjectFilter, ld as setReplicationCursor, fS as setSyncDaemonError, dS as setSyncDaemonOk, mS as setSyncDaemonPhase, ed as setSyncResetState, cS as shouldSkipOfflinePeer, mr as signRequest, qr as startMaintenanceJob, $n as storePrivateKeyKeychain, As as storeVectors, Tt as stripJsonComments, Xg as stripPrivate, e_ as stripPrivateObj, Et as stripTrailingCommas, of as summarizeInboundScopeRejections, gS as syncDaemonTick, eS as syncOnce, $x as syncPassPreflight, Nd as syncProjectAllowedByFilters, AS as syncScopeResetRequiredPayload, Pd as syncVisibilityAllowed, X as tableExists, Wo as timeline, Z as toJson, Gn as toJsonNullable, Jr as updateMaintenanceJob, hx as updatePeerAddresses, yu as upsertCachedScopeMemberships, Vh as upsertCoordinatorGroupPreference, Ab as upsertProjectScopeSettingsMapping, ai as vacuumDatabase, ur as validateExistingKeypair, hr as verifySignature, Bt as writeCodememConfigFile, Vt as writeWorkspaceCodememConfigFile };
18442
+ export { Oe as Api, Xe as BetterSqliteCoordinatorStore, Ft as CODEMEM_CONFIG_ENV_OVERRIDES, Uh as DEDUP_KEY_BACKFILL_JOB, z as DEFAULT_COORDINATOR_DB_PATH, En as DEFAULT_DB_PATH, tu as DEFAULT_SCOPE_MEMBERSHIP_CACHE_MAX_AGE_MS, hx as DEFAULT_SERVICE_TYPE, Lu as DEFAULT_SYNC_SCOPE_ID, o as DEFAULT_TIME_WINDOW_S, qh as DedupKeyBackfillRunner, si as INJECTION_EVAL_SCENARIO_PACKS, Wv as LEGACY_SHARED_REVIEW_SCOPE_ID, Ei as LOCAL_DEFAULT_SCOPE_ID, dy as LOCAL_SYNC_CAPABILITY, o_ as LOW_SIGNAL_TOOLS, Sr as MAPPABLE_CLAUDE_HOOK_EVENTS, Cn as MIN_COMPATIBLE_SCHEMA, ke as MUTATING_TOOL_NAMES, If as MemoryStore, Ip as ObserverAuthAdapter, cm as ObserverAuthError, Nm as ObserverClient, zb as REF_BACKFILL_JOB, Ig as RICH_TIER_DEFAULTS, Rb as RawEventSweeper, Gb as RefBackfillRunner, Sn as SCHEMA_VERSION, Gv as SCOPE_BACKFILL_JOB, n as SCOPE_MEMBERSHIP_REVOCATION_LIMITATION, Kb as SESSION_CONTEXT_BACKFILL_JOB, fr as SIGNATURE_VERSION, Fg as SIMPLE_TIER_DEFAULTS, ox as SUMMARY_DEDUP_BACKFILL_JOB, ly as SYNC_CAPABILITIES, uy as SYNC_CAPABILITY_HEADER, kS as SYNC_SCOPE_QUERY_PARAM, sy as ScopeBackfillRunner, ax as SessionContextBackfillRunner, px as SummaryDedupBackfillRunner, OS as SyncRetentionRunner, P_ as TRIVIAL_REQUESTS, gy as VECTOR_MODEL_MIGRATION_JOB, zS as VERSION, Ry as VectorModelMigrationRunner, es as _resetEmbeddingClient, MS as addSyncScopeToBoundary, Tl as addressDedupeKey, jx as advertiseMdns, Jm as aiBackfillStructuredContent, kb as analyzeProjectScopeMappingChangeGuardrails, qy as applyBootstrapSnapshot, mf as applyReplicationOps, zn as assertSchemaReady, gp as backfillMemoryDedupKeys, dp as backfillNarrativeFromBody, df as backfillReplicationOps, ry as backfillScopeIds, tp as backfillTagsText, js as backfillVectors, hn as bootstrapSchema, v_ as budgetToolEvents, _r as buildAuthHeaders, Al as buildBaseUrl, pr as buildCanonicalRequest, Ap as buildCodexHeaders, Yi as buildFilterClauses, Xi as buildFilterClausesWithContext, ig as buildImportKey, zr as buildIngestPayloadFromHook, $c as buildMemoryPack, tl as buildMemoryPackAsync, el as buildMemoryPackTrace, nl as buildMemoryPackTraceAsync, M_ as buildObserverPrompt, Rr as buildRawEventEnvelopeFromHook, Ev as buildSessionContext, U_ as buildTranscript, wd as bulkPruneReplicationOpsByAgeCutoff, mi as canonicalMemoryKind, Mi as canonicalWorkspaceIdentity, id as chunkOpsBySize, Qo as chunkText, Jv as classifyLegacyMemoryScope, yv as cleanOrphanSessions, yr as cleanupNonces, ga as clearMemoryRefs, pd as clockTuple, Kf as compareMemoryRoleReports, Yr as completeMaintenanceJob, Mn as connect, Ye as connectCoordinator, lS as consecutiveConnectivityFailures, mh as coordinatorArchiveGroupAction, fh as coordinatorCreateGroupAction, kh as coordinatorCreateInviteAction, vh as coordinatorCreateScopeAction, Eh as coordinatorDisableDeviceAction, Dh as coordinatorEnableDeviceAction, Hl as coordinatorEnabled, Ch as coordinatorEnrollDeviceAction, xh as coordinatorGrantScopeMembershipAction, Ah as coordinatorImportInviteAction, Nh as coordinatorListBootstrapGrantsAction, wh as coordinatorListDevicesAction, gh as coordinatorListGroupsAction, jh as coordinatorListJoinRequestsAction, bh as coordinatorListScopeMembershipsAction, _h as coordinatorListScopesAction, Oh as coordinatorRemoveDeviceAction, Th as coordinatorRenameDeviceAction, ph as coordinatorRenameGroupAction, Mh as coordinatorReviewJoinRequestAction, Ph as coordinatorRevokeBootstrapGrantAction, Sh as coordinatorRevokeScopeMembershipAction, $l as coordinatorStatusSnapshot, hh as coordinatorUnarchiveGroupAction, yh as coordinatorUpdateScopeAction, br as createBetterSqliteCoordinatorApp, c as createCoordinatorApp, Zl as createCoordinatorReciprocalApproval, zx as cursorAdvances, cp as deactivateLowSignalMemories, sp as deactivateLowSignalObservations, qg as decideExtractionReplayTier, s as decodeInvitePayload, lp as dedupNearDuplicateMemories, Ko as dedupeOrderedIds, Fh as defaultSpaceScopeIdForGroup, Hh as deleteCoordinatorGroupPreference, Pb as deleteProjectScopeSettingsMapping, H_ as deriveRequest, Iu as deriveTags, Mx as discoverPeersViaMdns, rs as embedTexts, t as encodeInvitePayload, dr as ensureDeviceIdentity, Zr as ensureMaintenanceJobsSchema, yn as ensureSchemaBootstrapped, Xv as ensureScopeBackfillScopes, su as ensureScopeMembershipCacheStateTable, Hs as estimateTokens, Ng as evaluateSessionExtractionItems, d_ as eventToToolEvent, qa as expandQuery, Xo as explain, e as explainScopeMembershipRevocation, pg as exportMemories, p_ as extractAdapterEvent, Ae as extractApplyPatchPaths, W_ as extractAssistantMessages, G_ as extractAssistantUsage, r as extractInvitePayload, up as extractNarrativeFromBody, Tp as extractOAuthAccess, Op as extractOAuthAccountId, kp as extractOAuthExpires, K_ as extractPrompts, Ep as extractProviderApiKey, fd as extractReplicationOps, f_ as extractToolEvents, Xr as failMaintenanceJob, By as fetchAllSnapshotPages, Yl as fetchCoordinatorStalePeers, Fu as fileTags, qd as filterReplicationOpsForSync, Kd as filterReplicationOpsForSyncWithStatus, ba as findByConcept, ya as findByFile, i as fingerprintPublicKey, V_ as firstSentence, Ov as flushRawEvents, wl as formatHostPort, Un as fromJson, Wn as fromJsonStrict, sr as generateKeypair, Mu as getCachedScopeAuthorization, Lt as getCodememConfigPath, Ht as getCodememEnvOverrides, zh as getCoordinatorGroupPreference, ns as getEmbeddingClient, Tg as getExtractionBenchmarkProfile, oi as getInjectionEvalScenarioByPrompt, ci as getInjectionEvalScenarioPack, li as getInjectionEvalScenarioPrompts, Q as getMaintenanceJob, Gf as getMemoryRoleReport, Wt as getOpenCodeProviderConfig, sn as getProviderApiKey, an as getProviderBaseUrl, on as getProviderHeaders, rn as getProviderOptions, ri as getRawEventRelinkPlan, ni as getRawEventRelinkReport, qf as getRawEventStatus, Yf as getReliabilityMetrics, cd as getReplicationCursor, Rn as getSchemaVersion, Ts as getSemanticIndexDiagnostics, Pg as getSessionExtractionEval, Mg as getSessionExtractionEvalScenario, di as getSummaryMetadata, gS as getSyncDaemonPhase, $u as getSyncResetState, At as getWorkspaceCodememConfigPath, jt as getWorkspaceScopedCodememConfigPath, av as hasMeaningfulObservation, Wh as hasPendingDedupKeyBackfill, Vb as hasPendingRefBackfill, ey as hasPendingScopeBackfill, nx as hasPendingSessionContextBackfill, cx as hasPendingSummaryDedupBackfill, xd as hasUnsyncedSharedMemoryChanges, Zo as hashText, Cg as importMemories, _v as ingest, bv as ingestMain, ii as initDatabase, IS as initTestSchema, LS as insertTestSession, l as inviteLink, cS as isConnectivityError, Ln as isEmbeddingDisabled, s_ as isInternalMemoryTool, ip as isLowSignalObservation, md as isNewerClock, py as isScopedSyncCapability, $g as isSensitiveFieldName, fi as isSummaryLikeMemory, B_ as isTrivialRequest, Ya as kindBonus, PS as listAuthorizedScopesForPeer, ju as listCachedScopesForDevice, Jt as listConfiguredOpenCodeProviders, Bh as listCoordinatorGroupPreferences, eu as listCoordinatorJoinRequests, Xl as listCoordinatorReciprocalApprovals, Gt as listCustomProviders, Eg as listExtractionBenchmarkProfiles, sf as listInboundScopeRejections, Kr as listMaintenanceJobs, Yt as listObserverProviderOptions, FS as listPerPeerScopeSyncState, Ab as listProjectScopeCandidates, jb as listProjectScopeInventory, wb as listProjectScopeSettingsMappings, Cb as listSharingDomainSettingsScopes, bd as loadMemorySnapshotPageForPeer, sm as loadObserverConfig, Dt as loadOpenCodeConfig, Sp as loadOpenCodeOAuthCache, _x as loadPeerAddresses, rr as loadPrivateKey, er as loadPrivateKeyKeychain, nr as loadPublicKey, yd as loadReplicationOpsForPeer, vd as loadReplicationOpsSince, In as loadSqliteVec, Gl as lookupCoordinatorPeers, Ir as mapClaudeHookPayload, Nx as mdnsAddressesForPeer, Tx as mdnsEnabled, El as mergeAddresses, ag as mergeSummaryMetadata, jn as migrateLegacyDbPath, uf as migrateLegacyImportKeys, hy as negotiateSyncCapability, J_ as normalizeAdapterEvents, Cl as normalizeAddress, ha as normalizeConcept, q_ as normalizeEventsForSessionContext, rp as normalizeObservation, Dr as normalizeProjectLabel, z_ as normalizeRequestText, my as normalizeSyncCapability, Pu as normalizeTag, c_ as normalizeToolName, iv as parseObserverResponse, wa as parsePositiveMemoryId, Ca as parseStrictInteger, AS as parseSyncScopeRequest, uS as peerBackoffSeconds, Rd as peerCanSyncPrivateOpByPersonalScopeGrant, Fd as personalScopeGrantStatusForPeer, Td as planReplicationOpsAgePrune, _a as populateMemoryRefs, Dp as probeAvailableCredentials, m_ as projectAdapterToolEvent, yi as projectBasename, Si as projectClause, xi as projectColumnClause, Ci as projectMatchesFilter, Sd as pruneReplicationOps, Cd as pruneReplicationOpsUntilCaughtUp, Xf as rawEventsGate, Np as readAuthFile, Rt as readCodememConfigFile, zt as readCodememConfigFileAtPath, Vl as readCoordinatorSyncConfig, mg as readImportPayload, Pt as readWorkspaceCodememConfigFile, Mb as reassignProjectScopeInventoryProject, Ja as recencyScore, vr as recordNonce, bx as recordPeerSuccess, hd as recordReplicationOp, yx as recordSyncAttempt, yp as redactText, Au as refreshConfiguredScopeMembershipCache, ku as refreshScopeMembershipCache, Jl as refreshStoredCoordinatorPeerAddresses, Wl as registerCoordinatorPresence, af as rejectInboundScopeFailures, Bp as renderObserverHeaders, Hv as replayBatchExtraction, Uv as replayBatchExtractionWithTierRouting, Ld as replicationOpRequiresPersonalScopeAuthorization, jl as requestJson, zo as rerankResults, Zt as resolveBuiltInProviderDefaultModel, Xt as resolveBuiltInProviderFromModel, Qt as resolveBuiltInProviderModel, It as resolveCodememConfigPath, cn as resolveCustomProviderDefaultModel, $t as resolveCustomProviderFromModel, ln as resolveCustomProviderModel, Dn as resolveDbPath, Ar as resolveHookProject, tr as resolveKeyPaths, Cp as resolveOAuthProvider, en as resolvePlaceholder, Ti as resolveProject, Vi as resolveProjectScope, Jf as retryRawEventFailures, jp as runAuthCommand, Kh as runDedupKeyBackfillPass, Wb as runRefBackfillPass, oy as runScopeBackfillPass, rx as runSessionContextBackfillPass, fx as runSummaryDedupBackfillPass, bS as runSyncDaemon, iS as runSyncPass, Ly as runVectorMigrationPass, n_ as sanitizePayload, a_ as sanitizeToolOutput, nh as scanSecretsRetroactive, H as schema, jS as scopeAuthorizationFailureReason, a as scopeMembershipEpochStatus, Bo as search, RS as seedMixedScopeFixture, gx as selectDialAddresses, Ms as semanticSearch, as as serializeFloat32, Sx as setPeerLocalActorClaim, xx as setPeerProjectFilter, ld as setReplicationCursor, hS as setSyncDaemonError, mS as setSyncDaemonOk, _S as setSyncDaemonPhase, ed as setSyncResetState, dS as shouldSkipOfflinePeer, mr as signRequest, qr as startMaintenanceJob, $n as storePrivateKeyKeychain, As as storeVectors, Tt as stripJsonComments, Xg as stripPrivate, e_ as stripPrivateObj, Et as stripTrailingCommas, of as summarizeInboundScopeRejections, yS as syncDaemonTick, rS as syncOnce, nS as syncPassPreflight, Nd as syncProjectAllowedByFilters, NS as syncScopeResetRequiredPayload, Pd as syncVisibilityAllowed, X as tableExists, Wo as timeline, Z as toJson, Gn as toJsonNullable, Jr as updateMaintenanceJob, vx as updatePeerAddresses, yu as upsertCachedScopeMemberships, Vh as upsertCoordinatorGroupPreference, Nb as upsertProjectScopeSettingsMapping, ai as vacuumDatabase, ur as validateExistingKeypair, hr as verifySignature, Bt as writeCodememConfigFile, Vt as writeWorkspaceCodememConfigFile };
18395
18443
 
18396
18444
  //# sourceMappingURL=index.js.map