@inerrata-corporation/errata 2.0.17-dev.3421 → 2.0.17-dev.3433

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.
@@ -15884,13 +15884,13 @@ function loadNodeSqlite() {
15884
15884
  process.emitWarning = original;
15885
15885
  }
15886
15886
  }
15887
- function openDatabase(path) {
15888
- const db = new DatabaseSync(path);
15887
+ function openDatabase(path, opts) {
15888
+ const db = opts ? new DatabaseSync(path, opts) : new DatabaseSync(path);
15889
15889
  try {
15890
15890
  db.exec("PRAGMA foreign_keys = ON");
15891
15891
  } catch {
15892
15892
  }
15893
- if (path !== ":memory:") {
15893
+ if (path !== ":memory:" && !opts?.readOnly) {
15894
15894
  try {
15895
15895
  db.exec("PRAGMA journal_mode = WAL");
15896
15896
  db.exec("PRAGMA synchronous = NORMAL");
@@ -16157,8 +16157,9 @@ init_src2();
16157
16157
  init_src();
16158
16158
 
16159
16159
  // ../../packages/local-graph/src/history-cache-floor.ts
16160
+ var HISTORY_CACHE_FLOOR_KEY = "history-cache-withdrawal-floor-3";
16160
16161
  function installHistoryCacheFloor(db) {
16161
- const key = "history-cache-withdrawal-floor-3";
16162
+ const key = HISTORY_CACHE_FLOOR_KEY;
16162
16163
  if (db.prepare("SELECT value FROM store_meta WHERE key = ?").get(key)) return;
16163
16164
  db.transaction(() => {
16164
16165
  db.exec("DROP TRIGGER IF EXISTS history_cache_nodes_insert; DROP TRIGGER IF EXISTS history_cache_nodes_update;");
@@ -16320,6 +16321,7 @@ function localEdgeViolation(fromLabel, type, toLabel) {
16320
16321
  return verdict.ok ? null : verdict.reason ?? "edge rule violation";
16321
16322
  }
16322
16323
  var SCHEMA_VERSION = 6;
16324
+ var SESSION_REPAIR_KEY = "session-evidence-v1";
16323
16325
  var SESSION_EVIDENCE_PREDICATE = SESSION_EVIDENCE_FIELDS.map((field) => `instr(attrs_json, '${JSON.stringify(field)}') > 0`).join(" OR ");
16324
16326
  var SCHEMA_SQL = `
16325
16327
  CREATE TABLE IF NOT EXISTS schema_version (
@@ -16531,10 +16533,10 @@ var SqliteGraphStore = class {
16531
16533
  }
16532
16534
  this.db.exec(TEMPORAL_INDEX_SQL);
16533
16535
  installHistoryCacheFloor(this.db);
16534
- if (!this.db.prepare("SELECT value FROM store_meta WHERE key = 'session-evidence-v1'").get()) {
16536
+ if (!this.db.prepare("SELECT value FROM store_meta WHERE key = ?").get(SESSION_REPAIR_KEY)) {
16535
16537
  this.db.transaction(() => {
16536
16538
  this.repairSessionAliases();
16537
- this.db.prepare("INSERT OR REPLACE INTO store_meta (key, value) VALUES ('session-evidence-v1', 'done')").run();
16539
+ this.db.prepare("INSERT OR REPLACE INTO store_meta (key, value) VALUES (?, 'done')").run(SESSION_REPAIR_KEY);
16538
16540
  });
16539
16541
  }
16540
16542
  this.stmts = {
@@ -16729,6 +16731,34 @@ var SqliteGraphStore = class {
16729
16731
  const seqRow = this.db.prepare("SELECT value FROM store_meta WHERE key = 'ingest_seq'").get();
16730
16732
  this.ingestSeq = seqRow ? Number(seqRow.value) : 0;
16731
16733
  }
16734
+ strandedSymbols() {
16735
+ return this.db.prepare(`
16736
+ SELECT f.id AS fileId, e.to_id AS symbolId
16737
+ -- Start from the small File population. An unconstrained JOIN lets
16738
+ -- SQLite start at edges_live and visit every live edge in the graph.
16739
+ FROM nodes f CROSS JOIN edges e ON e.from_id = f.id
16740
+ LEFT JOIN nodes t ON t.id = e.to_id
16741
+ WHERE f.label = 'File' AND f.valid_to IS NULL AND e.valid_to IS NULL
16742
+ AND e.type IN ('DEFINES', 'CONTAINS')
16743
+ AND (t.id IS NULL OR t.valid_to IS NOT NULL)
16744
+ `).all();
16745
+ }
16746
+ fileIndexStates(ids) {
16747
+ if (ids.length === 0) return [];
16748
+ if (ids.length > 500) throw new RangeError("fileIndexStates accepts at most 500 ids per read");
16749
+ const rows = this.db.prepare(`
16750
+ SELECT f.id, f.last_updated_at AS lastUpdatedAt, f.valid_to AS validTo,
16751
+ CASE WHEN count(e.id) = 0 THEN
16752
+ (json_type(f.attrs_json, '$.symbolCount') IN ('integer','real') AND json_extract(f.attrs_json, '$.symbolCount') = 0)
16753
+ OR json_type(f.attrs_json, '$.indexSkipped') = 'text'
16754
+ ELSE max(CASE WHEN t.id IS NULL OR t.valid_to IS NOT NULL THEN 1 ELSE 0 END) = 0 END AS complete
16755
+ FROM nodes f
16756
+ LEFT JOIN edges e ON e.from_id = f.id AND e.valid_to IS NULL AND e.type IN ('DEFINES','CONTAINS')
16757
+ LEFT JOIN nodes t ON t.id = e.to_id
16758
+ WHERE f.id IN (${ids.map(() => "?").join(",")}) GROUP BY f.id
16759
+ `).all(...ids);
16760
+ return rows.map((row) => ({ ...row, complete: row.complete === 1 }));
16761
+ }
16732
16762
  /** Forward-migrate the on-disk schema to the current SCHEMA_VERSION. */
16733
16763
  migrate(from) {
16734
16764
  this.db.transaction(() => {
@@ -18265,17 +18295,8 @@ var STALL_MIN_SPAN_MS = 60 * 60 * 1e3;
18265
18295
 
18266
18296
  // src/reconcile.ts
18267
18297
  init_src3();
18268
- function isLive(n) {
18269
- return n != null && (n.validTo ?? null) === null;
18270
- }
18271
18298
  function findStrandedSymbols(store) {
18272
- const stranded = [];
18273
- for (const file2 of store.findNodesByLabel("File")) {
18274
- for (const e of store.outEdges(file2.id, ["DEFINES", "CONTAINS"])) {
18275
- if (!isLive(store.getNode(e.to))) stranded.push({ fileId: file2.id, symbolId: e.to });
18276
- }
18277
- }
18278
- return stranded;
18299
+ return store.strandedSymbols();
18279
18300
  }
18280
18301
 
18281
18302
  // src/package-index.ts
@@ -18618,6 +18639,17 @@ function sessionOriginKey(sessionId) {
18618
18639
  return "ws_" + createHash2("sha256").update(sessionId).digest("hex").slice(0, 12);
18619
18640
  }
18620
18641
 
18642
+ // src/session-registry.ts
18643
+ var SESSION_IDLE_MS = 20 * 6e4;
18644
+ function sessionsOf(node) {
18645
+ const s = node.attrs["sources"];
18646
+ return Array.isArray(s) ? s.filter((x) => typeof x === "string" && x.length > 0) : [];
18647
+ }
18648
+ function capturedOnlyBy(node, sessions) {
18649
+ const recorded = sessionsOf(node);
18650
+ return recorded.length > 0 && recorded.every((s) => sessions.has(s));
18651
+ }
18652
+
18621
18653
  // src/public-symbols.ts
18622
18654
  import { readFileSync, readdirSync, existsSync } from "node:fs";
18623
18655
  import { join } from "node:path";
@@ -19496,6 +19528,7 @@ function shareableContext(n, wireId) {
19496
19528
  function buildInstanceIngest(store, profile, daemonVersion, ignorePatterns = [], opts = {}) {
19497
19529
  const level = opts.level ?? 1;
19498
19530
  const noveltyOpts = opts.dedupCosine != null ? { dedupCosine: opts.dedupCosine } : {};
19531
+ const quarantine = opts.quarantinedSessions?.length ? new Set(opts.quarantinedSessions) : null;
19499
19532
  const ignored = (text) => ignorePatterns.length > 0 && ignorePatterns.some((p) => text.toLowerCase().includes(p));
19500
19533
  const originSessionOf = (n) => {
19501
19534
  const key = sessionOriginKey(n.attrs["sources"]?.[0]);
@@ -19564,6 +19597,7 @@ function buildInstanceIngest(store, profile, daemonVersion, ignorePatterns = [],
19564
19597
  candidates: 0,
19565
19598
  shipped: 0,
19566
19599
  cloudSourced: 0,
19600
+ quarantined: 0,
19567
19601
  falsePositive: 0,
19568
19602
  ignored: 0,
19569
19603
  watermarked: 0,
@@ -19579,7 +19613,8 @@ function buildInstanceIngest(store, profile, daemonVersion, ignorePatterns = [],
19579
19613
  sidecarNoLexicon: 0,
19580
19614
  sidecarNoSummary: 0,
19581
19615
  fileRefsSubstituted: 0,
19582
- fileRefLexiconMisses: 0
19616
+ fileRefLexiconMisses: 0,
19617
+ collapsedEdges: 0
19583
19618
  };
19584
19619
  const sharedCauses = /* @__PURE__ */ new Map();
19585
19620
  const causalQueue = store.findNodesByLabel("Problem").filter(
@@ -19614,6 +19649,10 @@ function buildInstanceIngest(store, profile, daemonVersion, ignorePatterns = [],
19614
19649
  composition.cloudSourced++;
19615
19650
  continue;
19616
19651
  }
19652
+ if (quarantine && capturedOnlyBy(n, quarantine)) {
19653
+ composition.quarantined++;
19654
+ continue;
19655
+ }
19617
19656
  if (n.attrs["resolvedAs"] === PROBLEM_RESOLUTION.FALSE_POSITIVE) {
19618
19657
  composition.falsePositive++;
19619
19658
  continue;
@@ -19800,7 +19839,13 @@ function buildInstanceIngest(store, profile, daemonVersion, ignorePatterns = [],
19800
19839
  ];
19801
19840
  const dedup = /* @__PURE__ */ new Map();
19802
19841
  for (const e of rawOuts) dedup.set(`${e.type}>${e.to}`, e);
19803
- const outs = [...dedup.values()].map((e) => ({ e, wireTo: semanticEndpoints.get(e.to) })).filter((x) => x.wireTo != null);
19842
+ const outs = [...dedup.values()].map((e) => ({ e, wireTo: semanticEndpoints.get(e.to) })).filter((x) => {
19843
+ if (x.wireTo === wireFrom) {
19844
+ composition.collapsedEdges++;
19845
+ return false;
19846
+ }
19847
+ return x.wireTo != null;
19848
+ });
19804
19849
  if (outs.length === 0) continue;
19805
19850
  const dg = digest(outs.map(({ e, wireTo }) => `${e.type}>${wireTo}`).sort());
19806
19851
  const owner = nodeOf(sourceId);
@@ -19945,7 +19990,8 @@ function buildDrainInstances(store, sharedStore, input) {
19945
19990
  },
19946
19991
  ...lexicon ? { lexicon } : {},
19947
19992
  ...fileLexicon ? { fileLexicon } : {},
19948
- ...input.project ? { project: input.project } : {}
19993
+ ...input.project ? { project: input.project } : {},
19994
+ ...input.quarantinedSessions?.length ? { quarantinedSessions: input.quarantinedSessions } : {}
19949
19995
  });
19950
19996
  return {
19951
19997
  batch,