@inerrata-corporation/errata 2.0.17-dev.3369 → 2.0.17-dev.3416

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.
@@ -16216,12 +16216,13 @@ function installHistoryCacheFloor(db) {
16216
16216
  }
16217
16217
 
16218
16218
  // ../../packages/local-graph/src/session-evidence.ts
16219
+ var arrays = /* @__PURE__ */ new Set(["sources", "recurrenceSources", "contributors", "inferredContributors", "citeSessions"]);
16220
+ var scalars = /* @__PURE__ */ new Set(["discriminatorSource", "originSession", "sessionId", "sourceSession"]);
16221
+ var SESSION_EVIDENCE_FIELDS = [...arrays, ...scalars, "citeAnchorHints"];
16219
16222
  function repairSessionEvidence(input, aliases = /* @__PURE__ */ new Map()) {
16220
16223
  const mapping = new Map(aliases);
16221
16224
  const uuid3 = "[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}";
16222
16225
  const codex = new RegExp(`^codex:(?:rollout-.*?)?(${uuid3})$`, "i");
16223
- const arrays = /* @__PURE__ */ new Set(["sources", "recurrenceSources", "contributors", "inferredContributors", "citeSessions"]);
16224
- const scalars = /* @__PURE__ */ new Set(["discriminatorSource", "originSession", "sessionId", "sourceSession"]);
16225
16226
  const discover = (value, key = "") => {
16226
16227
  if (typeof value === "string" && (arrays.has(key) || scalars.has(key) || key === "citeAnchorHints")) {
16227
16228
  const match = value.match(codex);
@@ -16319,6 +16320,7 @@ function localEdgeViolation(fromLabel, type, toLabel) {
16319
16320
  return verdict.ok ? null : verdict.reason ?? "edge rule violation";
16320
16321
  }
16321
16322
  var SCHEMA_VERSION = 6;
16323
+ var SESSION_EVIDENCE_PREDICATE = SESSION_EVIDENCE_FIELDS.map((field) => `instr(attrs_json, '${JSON.stringify(field)}') > 0`).join(" OR ");
16322
16324
  var SCHEMA_SQL = `
16323
16325
  CREATE TABLE IF NOT EXISTS schema_version (
16324
16326
  version INTEGER PRIMARY KEY
@@ -16411,6 +16413,10 @@ CREATE UNIQUE INDEX IF NOT EXISTS edges_triple ON edges(from_id, type, to_id);
16411
16413
  `;
16412
16414
  var TEMPORAL_INDEX_SQL = `
16413
16415
  CREATE INDEX IF NOT EXISTS nodes_live ON nodes(label, valid_to);
16416
+ CREATE INDEX IF NOT EXISTS nodes_live_count ON nodes(valid_to);
16417
+ CREATE INDEX IF NOT EXISTS nodes_live_recent ON nodes(label, last_updated_at DESC) WHERE valid_to IS NULL;
16418
+ CREATE INDEX IF NOT EXISTS nodes_session_evidence ON nodes(id) WHERE ${SESSION_EVIDENCE_PREDICATE};
16419
+ CREATE INDEX IF NOT EXISTS edges_session_evidence ON edges(id) WHERE ${SESSION_EVIDENCE_PREDICATE};
16414
16420
  -- Covering + partial index for labelFingerprint over the instance labels: the
16415
16421
  -- live-push probe runs it per workspace on a timer, and each hit used to read
16416
16422
  -- its table row. Partial, so it maintains a few thousand rows instead of adding
@@ -16780,12 +16786,13 @@ var SqliteGraphStore = class {
16780
16786
  });
16781
16787
  }
16782
16788
  repairSessionAliases(canonical, aliases = []) {
16789
+ if (canonical && aliases.length === 0) return 0;
16783
16790
  const mapping = new Map(aliases.map((alias) => [alias, canonical]));
16784
16791
  let changed = 0;
16785
16792
  for (const table of ["nodes", "edges"]) {
16786
16793
  const predicates = canonical ? aliases.map(() => "instr(attrs_json, ?) > 0") : ["instr(attrs_json, 'codex:') > 0", "instr(attrs_json, 'discriminatorSource') > 0"];
16787
16794
  if (!predicates.length) continue;
16788
- const rows = this.db.prepare(`SELECT id, attrs_json FROM ${table} WHERE ${predicates.join(" OR ")}`).all(...canonical ? aliases : []);
16795
+ const rows = this.db.prepare(`SELECT id, attrs_json FROM ${table} WHERE (${SESSION_EVIDENCE_PREDICATE}) AND (${predicates.join(" OR ")})`).all(...canonical ? aliases.map((alias) => JSON.stringify(alias)) : []);
16789
16796
  const update = this.db.prepare(`UPDATE ${table} SET attrs_json = ?${table === "edges" ? ", type = CASE WHEN type = 'CONFIRMS' AND json_extract(?, '$.provisional') = 1 THEN 'INDICATES' ELSE type END" : ""} WHERE id = ?`);
16790
16797
  for (const row of rows) {
16791
16798
  const attrs = JSON.stringify(repairSessionEvidence(JSON.parse(row.attrs_json), mapping));
@@ -17011,6 +17018,25 @@ var SqliteGraphStore = class {
17011
17018
  const rows = this.db.prepare("SELECT id FROM nodes WHERE label = ? AND valid_to IS NULL ORDER BY last_updated_at DESC LIMIT ?").all(label, Math.max(0, limit));
17012
17019
  return rows.map((r) => r.id);
17013
17020
  }
17021
+ recentOpenProblemCandidates(opts) {
17022
+ if (!Number.isSafeInteger(opts.limit) || opts.limit < 0) {
17023
+ throw new RangeError("candidate limit must be a non-negative safe integer");
17024
+ }
17025
+ return this.db.prepare(`SELECT id, description FROM nodes
17026
+ WHERE label = 'Problem' AND valid_to IS NULL
17027
+ AND json_extract(attrs_json, '$.resolvedAt') IS NULL
17028
+ AND json_type(attrs_json, '$.mergedInto') IS NULL
17029
+ AND (? IS NULL OR id != ?)
17030
+ AND (json_type(attrs_json, '$.workspaceId') IS NULL OR json_extract(attrs_json, '$.workspaceId') = ?)
17031
+ AND COALESCE(json_extract(attrs_json, '$.kind') = 'constraint', 0) = ?
17032
+ ORDER BY last_updated_at DESC, rowid ASC LIMIT ?`).all(
17033
+ opts.excludeId ?? null,
17034
+ opts.excludeId ?? null,
17035
+ opts.workspaceId,
17036
+ opts.constraint ? 1 : 0,
17037
+ opts.limit
17038
+ );
17039
+ }
17014
17040
  hasLiveNodes() {
17015
17041
  const r = this.db.prepare("SELECT EXISTS(SELECT 1 FROM nodes WHERE valid_to IS NULL) AS e").get();
17016
17042
  return r.e === 1;