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.
@@ -8602,6 +8602,18 @@ var COMMAND_ARTIFACT_PATTERNS = [
8602
8602
  /<local-command-stdout>[\s\S]*?<\/local-command-stdout>/i,
8603
8603
  /<local-command-stderr>[\s\S]*?<\/local-command-stderr>/i
8604
8604
  ];
8605
+ var LOW_SIGNAL_CONTEXT_PATTERNS = [
8606
+ /<environment_context\b[\s\S]*<\/environment_context>/i,
8607
+ /<turn_aborted>/i,
8608
+ /^#\s*AGENTS\.md\s+instructions\b[\s\S]*<INSTRUCTIONS>/i,
8609
+ /^\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,
8610
+ /^\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,
8611
+ /^\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,
8612
+ /^\s*---\s*END\s+OF\s+CONTEXT\s+SUMMARY\b/i,
8613
+ /^\s*\[Your\s+active\s+task\s+list\s+was\s+preserved\s+across\s+context\s+compression\]/i,
8614
+ /^➜\s+\S+\s+git:\([^)]*\)\s+/i,
8615
+ /^\$\s+\S+/i
8616
+ ];
8605
8617
  var CONTINUATION_QUERY_PATTERNS = [
8606
8618
  /^\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,
8607
8619
  /^\s*(?:응\s*)?(?:이어서(?:\s*진행(?:해줘)?)?|계속(?:\s*해줘)?|다음\s*(?:단계|작업|추천\s*작업|추천|할\s*일)?(?:은|는)?(?:\s*(?:뭐야|진행(?:해줘)?))?\??|남은\s*(?:추가(?:로)?\s*)?(?:(?:할\s*만한\s*)?(?:작업|일)|할\s*일)?(?:은|는)?\s*(?:있어|있나|있나요|뭐야)\??|추천\s*작업(?:은|는)?(?:\s*뭐야)?\??|진행해줘)\s*$/i
@@ -8613,7 +8625,7 @@ var SHORT_REPAIR_FOLLOW_UP_PATTERNS = [
8613
8625
  var CURRENT_STATE_QUERY_PATTERNS = [
8614
8626
  /\bcurrent\b.*\b(?:state|status|deployment|blocker|pr|pull request)\b/i,
8615
8627
  /\b(?:still|as current|current)\b.*\b(?:unresolved|open|pending|not completed)\b/i,
8616
- /\b(?:old|obsolete|stale|resolved|already resolved)\b.*\b(?:current|still|unresolved|open|state|status)\b/i,
8628
+ /\b(?:old|obsolete|stale|resolved|already resolved)\b.*\b(?:current|still|unresolved|open|status)\b/i,
8617
8629
  /(?:현재|아직|이전|오래된|해결된).*(?:상태|미해결|열린|블로커|PR|풀리퀘스트)/i
8618
8630
  ];
8619
8631
  var STALE_CONTENT_PATTERNS = [
@@ -8759,6 +8771,21 @@ function isCommandArtifactQuery(query) {
8759
8771
  if (normalized.includes("command-name") || normalized.includes("command-message")) return true;
8760
8772
  return COMMAND_ARTIFACT_PATTERNS.some((pattern) => pattern.test(trimmed));
8761
8773
  }
8774
+ function isCommandArtifactContent(content) {
8775
+ const trimmed = content.trim();
8776
+ if (!trimmed) return false;
8777
+ const normalized = trimmed.toLowerCase();
8778
+ if (normalized.includes("local-command-stdout") || normalized.includes("local-command-stderr")) return true;
8779
+ if (normalized.includes("command-name") || normalized.includes("command-message")) return true;
8780
+ return COMMAND_ARTIFACT_PATTERNS.some((pattern) => pattern.test(trimmed));
8781
+ }
8782
+ function isLowSignalContextContent(content) {
8783
+ const trimmed = content.trim();
8784
+ if (!trimmed) return true;
8785
+ if (isCommandArtifactContent(trimmed)) return true;
8786
+ if (LOW_SIGNAL_CONTEXT_PATTERNS.some((pattern) => pattern.test(trimmed))) return true;
8787
+ return false;
8788
+ }
8762
8789
  function isGenericContinuationQuery(query) {
8763
8790
  const trimmed = query.trim();
8764
8791
  if (!trimmed) return false;
@@ -8776,6 +8803,16 @@ function isShortRepairFollowUpQuery(query) {
8776
8803
  if (tokens.length > 8) return false;
8777
8804
  return SHORT_REPAIR_FOLLOW_UP_PATTERNS.some((pattern) => pattern.test(trimmed));
8778
8805
  }
8806
+ function isLowConfidenceContextFallbackQuery(query) {
8807
+ const trimmed = query.trim();
8808
+ if (!trimmed) return false;
8809
+ if (isGenericContinuationQuery(trimmed) || isShortRepairFollowUpQuery(trimmed)) return true;
8810
+ const terms = new Set(tokenizeQualityText(trimmed));
8811
+ if ((terms.has("compacted") || terms.has("compaction")) && terms.has("handoff")) return false;
8812
+ const hasContinuationRecall = /^(?:continue|resume)\b/i.test(trimmed) && (terms.has("work") || terms.has("step") || terms.has("task") || terms.has("last") || terms.has("completed"));
8813
+ 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"));
8814
+ return hasContinuationRecall || hasValidationGateRecall;
8815
+ }
8779
8816
  function isCurrentStateQuery(query) {
8780
8817
  const trimmed = query.trim();
8781
8818
  if (!trimmed) return false;
@@ -9043,7 +9080,14 @@ var Retriever = class {
9043
9080
  };
9044
9081
  fallbackTrace.push("fallback:summary");
9045
9082
  }
9046
- const memories = await this.enrichResults(current.results.slice(0, opts.topK), opts);
9083
+ const selectedResults = current.results.slice(0, opts.topK).filter((result) => {
9084
+ if (current.matchResult.confidence !== "none") return true;
9085
+ if (isLowConfidenceContextFallbackQuery(query)) {
9086
+ return (result.semanticScore ?? result.score) >= 0.5 || result.score >= 0.5;
9087
+ }
9088
+ return (result.semanticScore ?? result.score) >= 0.62 || result.score >= 0.62;
9089
+ });
9090
+ const memories = await this.enrichResults(selectedResults, opts, query);
9047
9091
  const context = this.buildContext(memories, opts.maxTokens);
9048
9092
  return {
9049
9093
  memories,
@@ -9051,7 +9095,7 @@ var Retriever = class {
9051
9095
  totalTokens: this.estimateTokens(context),
9052
9096
  context,
9053
9097
  fallbackTrace,
9054
- selectedDebug: current.results.slice(0, opts.topK).map((r) => this.debugDetailForResult(r)),
9098
+ selectedDebug: selectedResults.map((r) => this.debugDetailForResult(r)),
9055
9099
  candidateDebug: (current.candidateResults || []).slice(0, Math.max(opts.topK * 3, 20)).map((r) => this.debugDetailForResult(r)),
9056
9100
  rawQueryText: current.queryRewriteKind ? query : void 0,
9057
9101
  effectiveQueryText: current.effectiveQueryText,
@@ -9146,6 +9190,7 @@ var Retriever = class {
9146
9190
  if (isCurrentStateQuery(options.query)) {
9147
9191
  filtered = filtered.filter((result) => !isStaleOrSupersededContent(result.content));
9148
9192
  }
9193
+ filtered = filtered.filter((result) => !isLowSignalContextContent(result.content));
9149
9194
  filtered = filtered.filter(
9150
9195
  (result) => this.isGraphPathResult(result) || hasDiscriminativeTermOverlap(options.query, result.content)
9151
9196
  );
@@ -9486,7 +9531,7 @@ var Retriever = class {
9486
9531
  async retrieveRecent(limit = 100) {
9487
9532
  return this.eventStore.getRecentEvents(limit);
9488
9533
  }
9489
- async enrichResults(results, options) {
9534
+ async enrichResults(results, options, query) {
9490
9535
  const memories = [];
9491
9536
  for (const result of results) {
9492
9537
  const event = await this.eventStore.getEvent(result.eventId);
@@ -9496,13 +9541,13 @@ var Retriever = class {
9496
9541
  }
9497
9542
  let sessionContext;
9498
9543
  if (options.includeSessionContext) {
9499
- sessionContext = await this.getSessionContext(event.sessionId, event.id);
9544
+ sessionContext = await this.getSessionContext(event.sessionId, event.id, query);
9500
9545
  }
9501
9546
  memories.push({ event, score: result.score, sessionContext });
9502
9547
  }
9503
9548
  return memories;
9504
9549
  }
9505
- async getSessionContext(sessionId, eventId) {
9550
+ async getSessionContext(sessionId, eventId, query) {
9506
9551
  const sessionEvents = await this.eventStore.getSessionEvents(sessionId);
9507
9552
  const eventIndex = sessionEvents.findIndex((e) => e.id === eventId);
9508
9553
  if (eventIndex === -1) return void 0;
@@ -9510,7 +9555,9 @@ var Retriever = class {
9510
9555
  const end = Math.min(sessionEvents.length, eventIndex + 2);
9511
9556
  const contextEvents = sessionEvents.slice(start, end);
9512
9557
  if (contextEvents.length <= 1) return void 0;
9513
- return contextEvents.filter((e) => e.id !== eventId).map((e) => `[${e.eventType}]: ${e.content.slice(0, 200)}...`).join("\n");
9558
+ const suppressStaleState = isCurrentStateQuery(query);
9559
+ 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)}...`);
9560
+ return contextLines.length > 0 ? contextLines.join("\n") : void 0;
9514
9561
  }
9515
9562
  buildUnifiedContext(projectResult, sharedMemories) {
9516
9563
  let context = projectResult.context;