claude-memory-layer 1.0.45 → 1.0.46

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.
@@ -8428,6 +8428,18 @@ var COMMAND_ARTIFACT_PATTERNS = [
8428
8428
  /<local-command-stdout>[\s\S]*?<\/local-command-stdout>/i,
8429
8429
  /<local-command-stderr>[\s\S]*?<\/local-command-stderr>/i
8430
8430
  ];
8431
+ var LOW_SIGNAL_CONTEXT_PATTERNS = [
8432
+ /<environment_context\b[\s\S]*<\/environment_context>/i,
8433
+ /<turn_aborted>/i,
8434
+ /^#\s*AGENTS\.md\s+instructions\b[\s\S]*<INSTRUCTIONS>/i,
8435
+ /^\s*(?:understood[,\s.]*)?(?:stopping|stopped|pausing|paused)\s+here\b[\s\S]{0,180}\blet\s+me\s+know\s+when\s+you(?:'d|\s+would)?\s+like\s+to\s+continue\b/i,
8436
+ /^\s*\[?CONTEXT\s+COMPACTION\s*[—-]\s*REFERENCE\s+ONLY\]?\b[\s\S]{0,600}\b(?:earlier\s+turns\s+were\s+compacted|handoff\s+from\s+a\s+previous\s+context\s+window|active\s+task)\b/i,
8437
+ /^\s*Summary\s+generation\s+was\s+unavailable\.\s*\d+\s+message\(s\)\s+were\s+removed\s+to\s+free\s+context\s+space\b/i,
8438
+ /^\s*---\s*END\s+OF\s+CONTEXT\s+SUMMARY\b/i,
8439
+ /^\s*\[Your\s+active\s+task\s+list\s+was\s+preserved\s+across\s+context\s+compression\]/i,
8440
+ /^➜\s+\S+\s+git:\([^)]*\)\s+/i,
8441
+ /^\$\s+\S+/i
8442
+ ];
8431
8443
  var CONTINUATION_QUERY_PATTERNS = [
8432
8444
  /^\s*(?:continue|resume|next|what(?:'s| is)? next|next\s+(?:step|task|action)|recommended\s+(?:next\s+)?(?:step|task|action)|what should (?:we|i) do next)\??\s*$/i,
8433
8445
  /^\s*(?:응\s*)?(?:이어서(?:\s*진행(?:해줘)?)?|계속(?:\s*해줘)?|다음\s*(?:단계|작업|추천\s*작업|추천|할\s*일)?(?:은|는)?(?:\s*(?:뭐야|진행(?:해줘)?))?\??|남은\s*(?:추가(?:로)?\s*)?(?:(?:할\s*만한\s*)?(?:작업|일)|할\s*일)?(?:은|는)?\s*(?:있어|있나|있나요|뭐야)\??|추천\s*작업(?:은|는)?(?:\s*뭐야)?\??|진행해줘)\s*$/i
@@ -8439,7 +8451,7 @@ var SHORT_REPAIR_FOLLOW_UP_PATTERNS = [
8439
8451
  var CURRENT_STATE_QUERY_PATTERNS = [
8440
8452
  /\bcurrent\b.*\b(?:state|status|deployment|blocker|pr|pull request)\b/i,
8441
8453
  /\b(?:still|as current|current)\b.*\b(?:unresolved|open|pending|not completed)\b/i,
8442
- /\b(?:old|obsolete|stale|resolved|already resolved)\b.*\b(?:current|still|unresolved|open|state|status)\b/i,
8454
+ /\b(?:old|obsolete|stale|resolved|already resolved)\b.*\b(?:current|still|unresolved|open|status)\b/i,
8443
8455
  /(?:현재|아직|이전|오래된|해결된).*(?:상태|미해결|열린|블로커|PR|풀리퀘스트)/i
8444
8456
  ];
8445
8457
  var STALE_CONTENT_PATTERNS = [
@@ -8585,6 +8597,21 @@ function isCommandArtifactQuery(query) {
8585
8597
  if (normalized.includes("command-name") || normalized.includes("command-message")) return true;
8586
8598
  return COMMAND_ARTIFACT_PATTERNS.some((pattern) => pattern.test(trimmed));
8587
8599
  }
8600
+ function isCommandArtifactContent(content) {
8601
+ const trimmed = content.trim();
8602
+ if (!trimmed) return false;
8603
+ const normalized = trimmed.toLowerCase();
8604
+ if (normalized.includes("local-command-stdout") || normalized.includes("local-command-stderr")) return true;
8605
+ if (normalized.includes("command-name") || normalized.includes("command-message")) return true;
8606
+ return COMMAND_ARTIFACT_PATTERNS.some((pattern) => pattern.test(trimmed));
8607
+ }
8608
+ function isLowSignalContextContent(content) {
8609
+ const trimmed = content.trim();
8610
+ if (!trimmed) return true;
8611
+ if (isCommandArtifactContent(trimmed)) return true;
8612
+ if (LOW_SIGNAL_CONTEXT_PATTERNS.some((pattern) => pattern.test(trimmed))) return true;
8613
+ return false;
8614
+ }
8588
8615
  function isGenericContinuationQuery(query) {
8589
8616
  const trimmed = query.trim();
8590
8617
  if (!trimmed) return false;
@@ -8602,6 +8629,16 @@ function isShortRepairFollowUpQuery(query) {
8602
8629
  if (tokens.length > 8) return false;
8603
8630
  return SHORT_REPAIR_FOLLOW_UP_PATTERNS.some((pattern) => pattern.test(trimmed));
8604
8631
  }
8632
+ function isLowConfidenceContextFallbackQuery(query) {
8633
+ const trimmed = query.trim();
8634
+ if (!trimmed) return false;
8635
+ if (isGenericContinuationQuery(trimmed) || isShortRepairFollowUpQuery(trimmed)) return true;
8636
+ const terms = new Set(tokenizeQualityText(trimmed));
8637
+ if ((terms.has("compacted") || terms.has("compaction")) && terms.has("handoff")) return false;
8638
+ const hasContinuationRecall = /^(?:continue|resume)\b/i.test(trimmed) && (terms.has("work") || terms.has("step") || terms.has("task") || terms.has("last") || terms.has("completed"));
8639
+ const hasValidationGateRecall = terms.has("validation") && (terms.has("gate") || terms.has("check")) && (terms.has("run") || terms.has("before") || terms.has("commit") || terms.has("committing") || terms.has("change"));
8640
+ return hasContinuationRecall || hasValidationGateRecall;
8641
+ }
8605
8642
  function isCurrentStateQuery(query) {
8606
8643
  const trimmed = query.trim();
8607
8644
  if (!trimmed) return false;
@@ -8869,7 +8906,14 @@ var Retriever = class {
8869
8906
  };
8870
8907
  fallbackTrace.push("fallback:summary");
8871
8908
  }
8872
- const memories = await this.enrichResults(current.results.slice(0, opts.topK), opts);
8909
+ const selectedResults = current.results.slice(0, opts.topK).filter((result) => {
8910
+ if (current.matchResult.confidence !== "none") return true;
8911
+ if (isLowConfidenceContextFallbackQuery(query)) {
8912
+ return (result.semanticScore ?? result.score) >= 0.5 || result.score >= 0.5;
8913
+ }
8914
+ return (result.semanticScore ?? result.score) >= 0.62 || result.score >= 0.62;
8915
+ });
8916
+ const memories = await this.enrichResults(selectedResults, opts, query);
8873
8917
  const context = this.buildContext(memories, opts.maxTokens);
8874
8918
  return {
8875
8919
  memories,
@@ -8877,7 +8921,7 @@ var Retriever = class {
8877
8921
  totalTokens: this.estimateTokens(context),
8878
8922
  context,
8879
8923
  fallbackTrace,
8880
- selectedDebug: current.results.slice(0, opts.topK).map((r) => this.debugDetailForResult(r)),
8924
+ selectedDebug: selectedResults.map((r) => this.debugDetailForResult(r)),
8881
8925
  candidateDebug: (current.candidateResults || []).slice(0, Math.max(opts.topK * 3, 20)).map((r) => this.debugDetailForResult(r)),
8882
8926
  rawQueryText: current.queryRewriteKind ? query : void 0,
8883
8927
  effectiveQueryText: current.effectiveQueryText,
@@ -8972,6 +9016,7 @@ var Retriever = class {
8972
9016
  if (isCurrentStateQuery(options.query)) {
8973
9017
  filtered = filtered.filter((result) => !isStaleOrSupersededContent(result.content));
8974
9018
  }
9019
+ filtered = filtered.filter((result) => !isLowSignalContextContent(result.content));
8975
9020
  filtered = filtered.filter(
8976
9021
  (result) => this.isGraphPathResult(result) || hasDiscriminativeTermOverlap(options.query, result.content)
8977
9022
  );
@@ -9312,7 +9357,7 @@ var Retriever = class {
9312
9357
  async retrieveRecent(limit = 100) {
9313
9358
  return this.eventStore.getRecentEvents(limit);
9314
9359
  }
9315
- async enrichResults(results, options) {
9360
+ async enrichResults(results, options, query) {
9316
9361
  const memories = [];
9317
9362
  for (const result of results) {
9318
9363
  const event = await this.eventStore.getEvent(result.eventId);
@@ -9322,13 +9367,13 @@ var Retriever = class {
9322
9367
  }
9323
9368
  let sessionContext;
9324
9369
  if (options.includeSessionContext) {
9325
- sessionContext = await this.getSessionContext(event.sessionId, event.id);
9370
+ sessionContext = await this.getSessionContext(event.sessionId, event.id, query);
9326
9371
  }
9327
9372
  memories.push({ event, score: result.score, sessionContext });
9328
9373
  }
9329
9374
  return memories;
9330
9375
  }
9331
- async getSessionContext(sessionId, eventId) {
9376
+ async getSessionContext(sessionId, eventId, query) {
9332
9377
  const sessionEvents = await this.eventStore.getSessionEvents(sessionId);
9333
9378
  const eventIndex = sessionEvents.findIndex((e) => e.id === eventId);
9334
9379
  if (eventIndex === -1) return void 0;
@@ -9336,7 +9381,9 @@ var Retriever = class {
9336
9381
  const end = Math.min(sessionEvents.length, eventIndex + 2);
9337
9382
  const contextEvents = sessionEvents.slice(start, end);
9338
9383
  if (contextEvents.length <= 1) return void 0;
9339
- return contextEvents.filter((e) => e.id !== eventId).map((e) => `[${e.eventType}]: ${e.content.slice(0, 200)}...`).join("\n");
9384
+ const suppressStaleState = isCurrentStateQuery(query);
9385
+ const contextLines = contextEvents.filter((e) => e.id !== eventId).filter((e) => !isLowSignalContextContent(e.content)).filter((e) => !(suppressStaleState && isStaleOrSupersededContent(e.content))).map((e) => `[${e.eventType}]: ${e.content.slice(0, 200)}...`);
9386
+ return contextLines.length > 0 ? contextLines.join("\n") : void 0;
9340
9387
  }
9341
9388
  buildUnifiedContext(projectResult, sharedMemories) {
9342
9389
  let context = projectResult.context;