@inerrata-corporation/errata 2.0.2-dev.506 → 2.0.2-dev.513

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.
@@ -16562,6 +16562,37 @@ var SqliteGraphStore = class {
16562
16562
  const rows = this.db.prepare("SELECT from_id, to_id, type FROM edges WHERE valid_to IS NULL").all();
16563
16563
  return rows.map((r) => ({ from: r.from_id, to: r.to_id, type: r.type }));
16564
16564
  }
16565
+ reviveReobserved(relPaths, workspaceId, since) {
16566
+ let revived = 0;
16567
+ const CHUNK = 400;
16568
+ for (let i = 0; i < relPaths.length; i += CHUNK) {
16569
+ const slice = relPaths.slice(i, i + CHUNK);
16570
+ if (slice.length === 0) continue;
16571
+ const r = this.db.prepare(
16572
+ `UPDATE nodes SET valid_to = NULL
16573
+ WHERE valid_to IS NOT NULL
16574
+ AND last_updated_at >= ?
16575
+ AND json_extract(attrs_json, '$.workspaceId') = ?
16576
+ AND json_extract(attrs_json, '$.relPath') IN (${slice.map(() => "?").join(",")})`
16577
+ ).run(since, workspaceId, ...slice);
16578
+ revived += Number(r.changes);
16579
+ }
16580
+ if (revived > 0) this.mutations++;
16581
+ return revived;
16582
+ }
16583
+ liveNodeIds(ids) {
16584
+ const live = /* @__PURE__ */ new Set();
16585
+ const CHUNK = 900;
16586
+ for (let i = 0; i < ids.length; i += CHUNK) {
16587
+ const slice = ids.slice(i, i + CHUNK);
16588
+ if (slice.length === 0) continue;
16589
+ const rows = this.db.prepare(
16590
+ `SELECT id FROM nodes WHERE valid_to IS NULL AND id IN (${slice.map(() => "?").join(",")})`
16591
+ ).all(...slice);
16592
+ for (const r of rows) live.add(r.id);
16593
+ }
16594
+ return live;
16595
+ }
16565
16596
  /**
16566
16597
  * Live edges WITH their endpoint labels and ids, resolved in ONE join.
16567
16598
  *
package/errata.mjs CHANGED
@@ -17237,6 +17237,37 @@ CREATE INDEX IF NOT EXISTS nodes_relpath ON nodes(json_extract(attrs_json, '$.re
17237
17237
  const rows = this.db.prepare("SELECT from_id, to_id, type FROM edges WHERE valid_to IS NULL").all();
17238
17238
  return rows.map((r) => ({ from: r.from_id, to: r.to_id, type: r.type }));
17239
17239
  }
17240
+ reviveReobserved(relPaths, workspaceId2, since) {
17241
+ let revived = 0;
17242
+ const CHUNK = 400;
17243
+ for (let i2 = 0; i2 < relPaths.length; i2 += CHUNK) {
17244
+ const slice = relPaths.slice(i2, i2 + CHUNK);
17245
+ if (slice.length === 0) continue;
17246
+ const r = this.db.prepare(
17247
+ `UPDATE nodes SET valid_to = NULL
17248
+ WHERE valid_to IS NOT NULL
17249
+ AND last_updated_at >= ?
17250
+ AND json_extract(attrs_json, '$.workspaceId') = ?
17251
+ AND json_extract(attrs_json, '$.relPath') IN (${slice.map(() => "?").join(",")})`
17252
+ ).run(since, workspaceId2, ...slice);
17253
+ revived += Number(r.changes);
17254
+ }
17255
+ if (revived > 0) this.mutations++;
17256
+ return revived;
17257
+ }
17258
+ liveNodeIds(ids) {
17259
+ const live = /* @__PURE__ */ new Set();
17260
+ const CHUNK = 900;
17261
+ for (let i2 = 0; i2 < ids.length; i2 += CHUNK) {
17262
+ const slice = ids.slice(i2, i2 + CHUNK);
17263
+ if (slice.length === 0) continue;
17264
+ const rows = this.db.prepare(
17265
+ `SELECT id FROM nodes WHERE valid_to IS NULL AND id IN (${slice.map(() => "?").join(",")})`
17266
+ ).all(...slice);
17267
+ for (const r of rows) live.add(r.id);
17268
+ }
17269
+ return live;
17270
+ }
17240
17271
  /**
17241
17272
  * Live edges WITH their endpoint labels and ids, resolved in ONE join.
17242
17273
  *
@@ -29636,6 +29667,7 @@ async function incrementalReindex(store, rootPath, workspaceId2, changedAbsPaths
29636
29667
  changedRelPaths
29637
29668
  });
29638
29669
  store.transaction(() => {
29670
+ store.reviveReobserved([...changedRelPaths], workspaceId2, t);
29639
29671
  const versionedAndFile = /* @__PURE__ */ new Set([...VERSIONED_LABELS, "File"]);
29640
29672
  const ownedLive = [];
29641
29673
  for (const n of store.nodesByRelPath([...changedRelPaths])) {
@@ -37796,9 +37828,13 @@ function* walkSource(dir) {
37796
37828
  function listSourceFiles(root) {
37797
37829
  return gitSourceFiles(root) ?? walkSource(root);
37798
37830
  }
37799
- function findStaleFiles(store, rootPath, workspaceId2) {
37831
+ async function findStaleFiles(store, rootPath, workspaceId2) {
37800
37832
  const stale = [];
37833
+ const pending = [];
37834
+ const allTargets = [];
37835
+ let scanned = 0;
37801
37836
  for (const abs of listSourceFiles(rootPath)) {
37837
+ if (++scanned % SCAN_YIELD_EVERY === 0) await new Promise((r) => setImmediate(r));
37802
37838
  let mtimeMs;
37803
37839
  try {
37804
37840
  mtimeMs = statSync2(abs).mtimeMs;
@@ -37815,11 +37851,21 @@ function findStaleFiles(store, rootPath, workspaceId2) {
37815
37851
  const edges = store.outEdges(fnode.id, ["DEFINES", "CONTAINS"]);
37816
37852
  if (edges.length === 0) {
37817
37853
  stale.push(abs);
37818
- } else if (edges.some((e) => !isLive(store.getNode(e.to)))) {
37819
- stale.push(abs);
37854
+ } else {
37855
+ const targets = edges.map((e) => e.to);
37856
+ pending.push({ abs, targets });
37857
+ allTargets.push(...targets);
37820
37858
  }
37821
37859
  }
37822
37860
  }
37861
+ const live = /* @__PURE__ */ new Set();
37862
+ for (let i2 = 0; i2 < allTargets.length; i2 += LIVENESS_CHUNK) {
37863
+ for (const id of store.liveNodeIds(allTargets.slice(i2, i2 + LIVENESS_CHUNK))) live.add(id);
37864
+ if (i2 + LIVENESS_CHUNK < allTargets.length) await new Promise((r) => setImmediate(r));
37865
+ }
37866
+ for (const { abs, targets } of pending) {
37867
+ if (targets.some((id) => !live.has(id))) stale.push(abs);
37868
+ }
37823
37869
  return stale;
37824
37870
  }
37825
37871
  function isLive(n) {
@@ -37835,7 +37881,7 @@ function findStrandedSymbols(store) {
37835
37881
  return stranded;
37836
37882
  }
37837
37883
  async function reconcileStaleFiles(store, rootPath, workspaceId2) {
37838
- const stale = findStaleFiles(store, rootPath, workspaceId2);
37884
+ const stale = await findStaleFiles(store, rootPath, workspaceId2);
37839
37885
  if (stale.length === 0) return 0;
37840
37886
  let total = 0;
37841
37887
  const BATCH = 20;
@@ -37846,13 +37892,15 @@ async function reconcileStaleFiles(store, rootPath, workspaceId2) {
37846
37892
  }
37847
37893
  return total;
37848
37894
  }
37849
- var IGNORED, SOURCE_RE;
37895
+ var IGNORED, SOURCE_RE, SCAN_YIELD_EVERY, LIVENESS_CHUNK;
37850
37896
  var init_reconcile = __esm({
37851
37897
  "src/reconcile.ts"() {
37852
37898
  "use strict";
37853
37899
  init_src11();
37854
37900
  IGNORED = /[\\/](?:\.git|node_modules|\.errata|dist|__pycache__)(?:[\\/]|$)/;
37855
37901
  SOURCE_RE = /\.(ts|tsx|js|jsx|mjs|cjs|py)$/i;
37902
+ SCAN_YIELD_EVERY = 100;
37903
+ LIVENESS_CHUNK = 4e3;
37856
37904
  }
37857
37905
  });
37858
37906
 
@@ -53812,7 +53860,7 @@ function startLoopLagMonitor(thresholdMs = 1e3) {
53812
53860
  }
53813
53861
 
53814
53862
  // src/engine.ts
53815
- var DAEMON_VERSION = true ? "2.0.2-dev.506" : "2.0.0-alpha.0";
53863
+ var DAEMON_VERSION = true ? "2.0.2-dev.513" : "2.0.0-alpha.0";
53816
53864
  var IGNORED_PATH = /[\\/](?:\.git|node_modules|\.errata|\.claude|\.codex|\.cursor|\.turbo|\.next|dist|coverage|test-results|playwright-report|__pycache__)(?:[\\/]|$)/;
53817
53865
  var IGNORED_NOISE = /castalia\.db|eventlog\.sqlite|turn-cursors/;
53818
53866
  var GIT_OP_MUTE_MS = 4e3;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inerrata-corporation/errata",
3
- "version": "2.0.2-dev.506",
3
+ "version": "2.0.2-dev.513",
4
4
  "description": "errata - local-first observation engine for AI coding agents",
5
5
  "type": "module",
6
6
  "bin": {
package/pass-worker.mjs CHANGED
@@ -16031,6 +16031,7 @@ async function incrementalReindex(store2, rootPath, workspaceId, changedAbsPaths
16031
16031
  changedRelPaths
16032
16032
  });
16033
16033
  store2.transaction(() => {
16034
+ store2.reviveReobserved([...changedRelPaths], workspaceId, t);
16034
16035
  const versionedAndFile = /* @__PURE__ */ new Set([...VERSIONED_LABELS, "File"]);
16035
16036
  const ownedLive = [];
16036
16037
  for (const n of store2.nodesByRelPath([...changedRelPaths])) {
@@ -24889,6 +24890,37 @@ var SqliteGraphStore = class {
24889
24890
  const rows = this.db.prepare("SELECT from_id, to_id, type FROM edges WHERE valid_to IS NULL").all();
24890
24891
  return rows.map((r) => ({ from: r.from_id, to: r.to_id, type: r.type }));
24891
24892
  }
24893
+ reviveReobserved(relPaths, workspaceId, since) {
24894
+ let revived = 0;
24895
+ const CHUNK = 400;
24896
+ for (let i2 = 0; i2 < relPaths.length; i2 += CHUNK) {
24897
+ const slice = relPaths.slice(i2, i2 + CHUNK);
24898
+ if (slice.length === 0) continue;
24899
+ const r = this.db.prepare(
24900
+ `UPDATE nodes SET valid_to = NULL
24901
+ WHERE valid_to IS NOT NULL
24902
+ AND last_updated_at >= ?
24903
+ AND json_extract(attrs_json, '$.workspaceId') = ?
24904
+ AND json_extract(attrs_json, '$.relPath') IN (${slice.map(() => "?").join(",")})`
24905
+ ).run(since, workspaceId, ...slice);
24906
+ revived += Number(r.changes);
24907
+ }
24908
+ if (revived > 0) this.mutations++;
24909
+ return revived;
24910
+ }
24911
+ liveNodeIds(ids) {
24912
+ const live = /* @__PURE__ */ new Set();
24913
+ const CHUNK = 900;
24914
+ for (let i2 = 0; i2 < ids.length; i2 += CHUNK) {
24915
+ const slice = ids.slice(i2, i2 + CHUNK);
24916
+ if (slice.length === 0) continue;
24917
+ const rows = this.db.prepare(
24918
+ `SELECT id FROM nodes WHERE valid_to IS NULL AND id IN (${slice.map(() => "?").join(",")})`
24919
+ ).all(...slice);
24920
+ for (const r of rows) live.add(r.id);
24921
+ }
24922
+ return live;
24923
+ }
24892
24924
  /**
24893
24925
  * Live edges WITH their endpoint labels and ids, resolved in ONE join.
24894
24926
  *
@@ -26708,9 +26740,15 @@ function* walkSource(dir) {
26708
26740
  function listSourceFiles(root) {
26709
26741
  return gitSourceFiles(root) ?? walkSource(root);
26710
26742
  }
26711
- function findStaleFiles(store2, rootPath, workspaceId) {
26743
+ var SCAN_YIELD_EVERY = 100;
26744
+ var LIVENESS_CHUNK = 4e3;
26745
+ async function findStaleFiles(store2, rootPath, workspaceId) {
26712
26746
  const stale = [];
26747
+ const pending = [];
26748
+ const allTargets = [];
26749
+ let scanned = 0;
26713
26750
  for (const abs of listSourceFiles(rootPath)) {
26751
+ if (++scanned % SCAN_YIELD_EVERY === 0) await new Promise((r) => setImmediate(r));
26714
26752
  let mtimeMs;
26715
26753
  try {
26716
26754
  mtimeMs = statSync2(abs).mtimeMs;
@@ -26727,18 +26765,25 @@ function findStaleFiles(store2, rootPath, workspaceId) {
26727
26765
  const edges = store2.outEdges(fnode.id, ["DEFINES", "CONTAINS"]);
26728
26766
  if (edges.length === 0) {
26729
26767
  stale.push(abs);
26730
- } else if (edges.some((e) => !isLive(store2.getNode(e.to)))) {
26731
- stale.push(abs);
26768
+ } else {
26769
+ const targets = edges.map((e) => e.to);
26770
+ pending.push({ abs, targets });
26771
+ allTargets.push(...targets);
26732
26772
  }
26733
26773
  }
26734
26774
  }
26775
+ const live = /* @__PURE__ */ new Set();
26776
+ for (let i2 = 0; i2 < allTargets.length; i2 += LIVENESS_CHUNK) {
26777
+ for (const id of store2.liveNodeIds(allTargets.slice(i2, i2 + LIVENESS_CHUNK))) live.add(id);
26778
+ if (i2 + LIVENESS_CHUNK < allTargets.length) await new Promise((r) => setImmediate(r));
26779
+ }
26780
+ for (const { abs, targets } of pending) {
26781
+ if (targets.some((id) => !live.has(id))) stale.push(abs);
26782
+ }
26735
26783
  return stale;
26736
26784
  }
26737
- function isLive(n) {
26738
- return n != null && (n.validTo ?? null) === null;
26739
- }
26740
26785
  async function reconcileStaleFiles(store2, rootPath, workspaceId) {
26741
- const stale = findStaleFiles(store2, rootPath, workspaceId);
26786
+ const stale = await findStaleFiles(store2, rootPath, workspaceId);
26742
26787
  if (stale.length === 0) return 0;
26743
26788
  let total = 0;
26744
26789
  const BATCH = 20;