claude-memory-layer 2.4.16 → 2.4.17

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.
@@ -1816,7 +1816,7 @@ function emptyLatencyAggregate() {
1816
1816
  return { count: 0, failedCount: 0, totalMs: 0, maxMs: 0 };
1817
1817
  }
1818
1818
  function runtimeVersion() {
1819
- const value = "2.4.16"?.trim();
1819
+ const value = "2.4.17"?.trim();
1820
1820
  return sanitizeRuntimeVersion(value || "development");
1821
1821
  }
1822
1822
  function sanitizeRuntimeVersion(value) {
@@ -206,7 +206,7 @@ function emptyLatencyAggregate() {
206
206
  return { count: 0, failedCount: 0, totalMs: 0, maxMs: 0 };
207
207
  }
208
208
  function runtimeVersion() {
209
- const value = "2.4.16"?.trim();
209
+ const value = "2.4.17"?.trim();
210
210
  return sanitizeRuntimeVersion(value || "development");
211
211
  }
212
212
  function sanitizeRuntimeVersion(value) {
@@ -21896,7 +21896,7 @@ async function main(options = {}) {
21896
21896
  triggerType: "session_start",
21897
21897
  deliveryClient,
21898
21898
  requestId: `${requestPrefix}:core`,
21899
- runtimeVersion: "2.4.16",
21899
+ runtimeVersion: "2.4.17",
21900
21900
  outcomeDiagnostics: {
21901
21901
  outcomeReason: "selected",
21902
21902
  laneCandidateCounts: {},
@@ -21957,7 +21957,7 @@ async function main(options = {}) {
21957
21957
  triggerType: "session_start",
21958
21958
  deliveryClient,
21959
21959
  requestId: `${requestPrefix}:lessons`,
21960
- runtimeVersion: "2.4.16",
21960
+ runtimeVersion: "2.4.17",
21961
21961
  outcomeDiagnostics: {
21962
21962
  outcomeReason: shownIds.length > 0 ? "selected" : "unknown",
21963
21963
  laneCandidateCounts: {},
@@ -22047,7 +22047,7 @@ You have worked on this project before. Here are some relevant memories:
22047
22047
  triggerType: "session_start",
22048
22048
  deliveryClient,
22049
22049
  requestId: `${requestPrefix}:recent`,
22050
- runtimeVersion: "2.4.16",
22050
+ runtimeVersion: "2.4.17",
22051
22051
  outcomeDiagnostics: {
22052
22052
  outcomeReason: "selected",
22053
22053
  laneCandidateCounts: {},
@@ -206,7 +206,7 @@ function emptyLatencyAggregate() {
206
206
  return { count: 0, failedCount: 0, totalMs: 0, maxMs: 0 };
207
207
  }
208
208
  function runtimeVersion() {
209
- const value = "2.4.16"?.trim();
209
+ const value = "2.4.17"?.trim();
210
210
  return sanitizeRuntimeVersion(value || "development");
211
211
  }
212
212
  function sanitizeRuntimeVersion(value) {
@@ -22550,7 +22550,7 @@ async function main(options = {}) {
22550
22550
  triggerType: "user_prompt",
22551
22551
  deliveryClient,
22552
22552
  requestId: retrievalRequestId,
22553
- runtimeVersion: "2.4.16",
22553
+ runtimeVersion: "2.4.17",
22554
22554
  outcomeDiagnostics
22555
22555
  });
22556
22556
  } catch {
@@ -254,7 +254,7 @@ function emptyLatencyAggregate() {
254
254
  return { count: 0, failedCount: 0, totalMs: 0, maxMs: 0 };
255
255
  }
256
256
  function runtimeVersion() {
257
- const value = "2.4.16"?.trim();
257
+ const value = "2.4.17"?.trim();
258
258
  return sanitizeRuntimeVersion(value || "development");
259
259
  }
260
260
  function sanitizeRuntimeVersion(value) {
@@ -260,7 +260,7 @@ function emptyLatencyAggregate() {
260
260
  return { count: 0, failedCount: 0, totalMs: 0, maxMs: 0 };
261
261
  }
262
262
  function runtimeVersion() {
263
- const value = "2.4.16"?.trim();
263
+ const value = "2.4.17"?.trim();
264
264
  return sanitizeRuntimeVersion(value || "development");
265
265
  }
266
266
  function sanitizeRuntimeVersion(value) {
@@ -254,7 +254,7 @@ function emptyLatencyAggregate() {
254
254
  return { count: 0, failedCount: 0, totalMs: 0, maxMs: 0 };
255
255
  }
256
256
  function runtimeVersion() {
257
- const value = "2.4.16"?.trim();
257
+ const value = "2.4.17"?.trim();
258
258
  return sanitizeRuntimeVersion(value || "development");
259
259
  }
260
260
  function sanitizeRuntimeVersion(value) {
@@ -258,7 +258,7 @@ function emptyLatencyAggregate() {
258
258
  return { count: 0, failedCount: 0, totalMs: 0, maxMs: 0 };
259
259
  }
260
260
  function runtimeVersion() {
261
- const value = "2.4.16"?.trim();
261
+ const value = "2.4.17"?.trim();
262
262
  return sanitizeRuntimeVersion(value || "development");
263
263
  }
264
264
  function sanitizeRuntimeVersion(value) {
@@ -20839,7 +20839,7 @@ async function main(options = {}) {
20839
20839
  triggerType: "session_start",
20840
20840
  deliveryClient,
20841
20841
  requestId: `${requestPrefix}:core`,
20842
- runtimeVersion: "2.4.16",
20842
+ runtimeVersion: "2.4.17",
20843
20843
  outcomeDiagnostics: {
20844
20844
  outcomeReason: "selected",
20845
20845
  laneCandidateCounts: {},
@@ -20900,7 +20900,7 @@ async function main(options = {}) {
20900
20900
  triggerType: "session_start",
20901
20901
  deliveryClient,
20902
20902
  requestId: `${requestPrefix}:lessons`,
20903
- runtimeVersion: "2.4.16",
20903
+ runtimeVersion: "2.4.17",
20904
20904
  outcomeDiagnostics: {
20905
20905
  outcomeReason: shownIds.length > 0 ? "selected" : "unknown",
20906
20906
  laneCandidateCounts: {},
@@ -20990,7 +20990,7 @@ You have worked on this project before. Here are some relevant memories:
20990
20990
  triggerType: "session_start",
20991
20991
  deliveryClient,
20992
20992
  requestId: `${requestPrefix}:recent`,
20993
- runtimeVersion: "2.4.16",
20993
+ runtimeVersion: "2.4.17",
20994
20994
  outcomeDiagnostics: {
20995
20995
  outcomeReason: "selected",
20996
20996
  laneCandidateCounts: {},
@@ -254,7 +254,7 @@ function emptyLatencyAggregate() {
254
254
  return { count: 0, failedCount: 0, totalMs: 0, maxMs: 0 };
255
255
  }
256
256
  function runtimeVersion() {
257
- const value = "2.4.16"?.trim();
257
+ const value = "2.4.17"?.trim();
258
258
  return sanitizeRuntimeVersion(value || "development");
259
259
  }
260
260
  function sanitizeRuntimeVersion(value) {
@@ -260,7 +260,7 @@ function emptyLatencyAggregate() {
260
260
  return { count: 0, failedCount: 0, totalMs: 0, maxMs: 0 };
261
261
  }
262
262
  function runtimeVersion() {
263
- const value = "2.4.16"?.trim();
263
+ const value = "2.4.17"?.trim();
264
264
  return sanitizeRuntimeVersion(value || "development");
265
265
  }
266
266
  function sanitizeRuntimeVersion(value) {
@@ -21498,7 +21498,7 @@ async function main(options = {}) {
21498
21498
  triggerType: "user_prompt",
21499
21499
  deliveryClient,
21500
21500
  requestId: retrievalRequestId,
21501
- runtimeVersion: "2.4.16",
21501
+ runtimeVersion: "2.4.17",
21502
21502
  outcomeDiagnostics
21503
21503
  });
21504
21504
  } catch {
package/dist/index.js CHANGED
@@ -4667,7 +4667,7 @@ function emptyLatencyAggregate() {
4667
4667
  return { count: 0, failedCount: 0, totalMs: 0, maxMs: 0 };
4668
4668
  }
4669
4669
  function runtimeVersion() {
4670
- const value = "2.4.16"?.trim();
4670
+ const value = "2.4.17"?.trim();
4671
4671
  return sanitizeRuntimeVersion(value || "development");
4672
4672
  }
4673
4673
  function sanitizeRuntimeVersion(value) {
@@ -25589,6 +25589,7 @@ function localizePulledMetadata(doc, localProject) {
25589
25589
  };
25590
25590
  return metadata;
25591
25591
  }
25592
+ var LATE_INSERT_WINDOW_MS = 30 * 60 * 1e3;
25592
25593
  function parseIntOrZero(value) {
25593
25594
  if (!value) return 0;
25594
25595
  const n = parseInt(value, 10);
@@ -25715,6 +25716,7 @@ var MongoSyncWorker = class {
25715
25716
  await this.events.createIndex({ projectKey: 1, seq: 1 }, { unique: true });
25716
25717
  await this.events.createIndex({ projectKey: 1, eventId: 1 }, { unique: true });
25717
25718
  await this.events.createIndex({ projectKey: 1, dedupeKey: 1 });
25719
+ await this.events.createIndex({ projectKey: 1, insertedAt: 1 });
25718
25720
  } catch (err) {
25719
25721
  console.warn("[MongoSyncWorker] Failed to ensure indexes (continuing):", err);
25720
25722
  }
@@ -25797,39 +25799,60 @@ var MongoSyncWorker = class {
25797
25799
  }
25798
25800
  return pushed;
25799
25801
  }
25802
+ /**
25803
+ * A pusher reserves its seq range before it inserts, so a document can appear below a cursor that another machine's
25804
+ * faster insert already moved past. Each pull therefore re-reads what was inserted shortly before the previous pull
25805
+ * started — import skips the events it already has — and then reads past the cursor as before. The window also
25806
+ * absorbs clock differences between machines (insertedAt is the pusher's clock).
25807
+ */
25800
25808
  async pullEvents() {
25801
25809
  if (!this.events) throw new Error("Mongo not connected");
25802
25810
  const position = await this.sqliteStore.getSyncPosition(this.pullTargetName());
25803
25811
  let lastSeq = parseIntOrZero(position.lastEventId);
25812
+ const startedAt = /* @__PURE__ */ new Date();
25813
+ const previousPullAt = position.lastTimestamp ? new Date(position.lastTimestamp) : null;
25804
25814
  let pulled = 0;
25815
+ if (lastSeq > 0 && previousPullAt && !Number.isNaN(previousPullAt.getTime())) {
25816
+ const since = new Date(previousPullAt.getTime() - LATE_INSERT_WINDOW_MS);
25817
+ let afterSeq = 0;
25818
+ while (true) {
25819
+ const docs = await this.events.find(
25820
+ { projectKey: this.config.projectKey, seq: { $gt: afterSeq, $lte: lastSeq }, insertedAt: { $gte: since } },
25821
+ { sort: { seq: 1 }, limit: this.config.batchSize }
25822
+ ).toArray();
25823
+ if (docs.length === 0) break;
25824
+ pulled += await this.importPulled(docs);
25825
+ afterSeq = docs[docs.length - 1].seq;
25826
+ if (docs.length < this.config.batchSize) break;
25827
+ }
25828
+ }
25805
25829
  while (true) {
25806
25830
  const docs = await this.events.find(
25807
25831
  { projectKey: this.config.projectKey, seq: { $gt: lastSeq } },
25808
25832
  { sort: { seq: 1 }, limit: this.config.batchSize }
25809
25833
  ).toArray();
25810
25834
  if (docs.length === 0) break;
25811
- const events = docs.map((d) => ({
25812
- id: d.eventId,
25813
- eventType: d.eventType,
25814
- sessionId: d.sessionId,
25815
- timestamp: d.timestamp instanceof Date ? d.timestamp : new Date(d.timestamp),
25816
- content: d.content,
25817
- canonicalKey: d.canonicalKey,
25818
- dedupeKey: d.dedupeKey,
25819
- metadata: this.config.localProject ? localizePulledMetadata(d, this.config.localProject) : d.metadata ?? void 0
25820
- }));
25821
- const result2 = await this.sqliteStore.importEvents(events);
25822
- pulled += result2.inserted;
25835
+ pulled += await this.importPulled(docs);
25823
25836
  lastSeq = docs[docs.length - 1].seq;
25824
- await this.sqliteStore.updateSyncPosition(
25825
- this.pullTargetName(),
25826
- String(lastSeq),
25827
- (/* @__PURE__ */ new Date()).toISOString()
25828
- );
25837
+ await this.sqliteStore.updateSyncPosition(this.pullTargetName(), String(lastSeq), startedAt.toISOString());
25829
25838
  if (docs.length < this.config.batchSize) break;
25830
25839
  }
25840
+ await this.sqliteStore.updateSyncPosition(this.pullTargetName(), String(lastSeq), startedAt.toISOString());
25831
25841
  return pulled;
25832
25842
  }
25843
+ async importPulled(docs) {
25844
+ const events = docs.map((d) => ({
25845
+ id: d.eventId,
25846
+ eventType: d.eventType,
25847
+ sessionId: d.sessionId,
25848
+ timestamp: d.timestamp instanceof Date ? d.timestamp : new Date(d.timestamp),
25849
+ content: d.content,
25850
+ canonicalKey: d.canonicalKey,
25851
+ dedupeKey: d.dedupeKey,
25852
+ metadata: this.config.localProject ? localizePulledMetadata(d, this.config.localProject) : d.metadata ?? void 0
25853
+ }));
25854
+ return (await this.sqliteStore.importEvents(events)).inserted;
25855
+ }
25833
25856
  };
25834
25857
 
25835
25858
  // src/core/product-validation-matrix.ts