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.
@@ -8780,6 +8780,18 @@ var COMMAND_ARTIFACT_PATTERNS = [
8780
8780
  /<local-command-stdout>[\s\S]*?<\/local-command-stdout>/i,
8781
8781
  /<local-command-stderr>[\s\S]*?<\/local-command-stderr>/i
8782
8782
  ];
8783
+ var LOW_SIGNAL_CONTEXT_PATTERNS = [
8784
+ /<environment_context\b[\s\S]*<\/environment_context>/i,
8785
+ /<turn_aborted>/i,
8786
+ /^#\s*AGENTS\.md\s+instructions\b[\s\S]*<INSTRUCTIONS>/i,
8787
+ /^\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,
8788
+ /^\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,
8789
+ /^\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,
8790
+ /^\s*---\s*END\s+OF\s+CONTEXT\s+SUMMARY\b/i,
8791
+ /^\s*\[Your\s+active\s+task\s+list\s+was\s+preserved\s+across\s+context\s+compression\]/i,
8792
+ /^➜\s+\S+\s+git:\([^)]*\)\s+/i,
8793
+ /^\$\s+\S+/i
8794
+ ];
8783
8795
  var CONTINUATION_QUERY_PATTERNS = [
8784
8796
  /^\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,
8785
8797
  /^\s*(?:응\s*)?(?:이어서(?:\s*진행(?:해줘)?)?|계속(?:\s*해줘)?|다음\s*(?:단계|작업|추천\s*작업|추천|할\s*일)?(?:은|는)?(?:\s*(?:뭐야|진행(?:해줘)?))?\??|남은\s*(?:추가(?:로)?\s*)?(?:(?:할\s*만한\s*)?(?:작업|일)|할\s*일)?(?:은|는)?\s*(?:있어|있나|있나요|뭐야)\??|추천\s*작업(?:은|는)?(?:\s*뭐야)?\??|진행해줘)\s*$/i
@@ -8791,7 +8803,7 @@ var SHORT_REPAIR_FOLLOW_UP_PATTERNS = [
8791
8803
  var CURRENT_STATE_QUERY_PATTERNS = [
8792
8804
  /\bcurrent\b.*\b(?:state|status|deployment|blocker|pr|pull request)\b/i,
8793
8805
  /\b(?:still|as current|current)\b.*\b(?:unresolved|open|pending|not completed)\b/i,
8794
- /\b(?:old|obsolete|stale|resolved|already resolved)\b.*\b(?:current|still|unresolved|open|state|status)\b/i,
8806
+ /\b(?:old|obsolete|stale|resolved|already resolved)\b.*\b(?:current|still|unresolved|open|status)\b/i,
8795
8807
  /(?:현재|아직|이전|오래된|해결된).*(?:상태|미해결|열린|블로커|PR|풀리퀘스트)/i
8796
8808
  ];
8797
8809
  var STALE_CONTENT_PATTERNS = [
@@ -8937,6 +8949,21 @@ function isCommandArtifactQuery(query) {
8937
8949
  if (normalized.includes("command-name") || normalized.includes("command-message")) return true;
8938
8950
  return COMMAND_ARTIFACT_PATTERNS.some((pattern) => pattern.test(trimmed));
8939
8951
  }
8952
+ function isCommandArtifactContent(content) {
8953
+ const trimmed = content.trim();
8954
+ if (!trimmed) return false;
8955
+ const normalized = trimmed.toLowerCase();
8956
+ if (normalized.includes("local-command-stdout") || normalized.includes("local-command-stderr")) return true;
8957
+ if (normalized.includes("command-name") || normalized.includes("command-message")) return true;
8958
+ return COMMAND_ARTIFACT_PATTERNS.some((pattern) => pattern.test(trimmed));
8959
+ }
8960
+ function isLowSignalContextContent(content) {
8961
+ const trimmed = content.trim();
8962
+ if (!trimmed) return true;
8963
+ if (isCommandArtifactContent(trimmed)) return true;
8964
+ if (LOW_SIGNAL_CONTEXT_PATTERNS.some((pattern) => pattern.test(trimmed))) return true;
8965
+ return false;
8966
+ }
8940
8967
  function isGenericContinuationQuery(query) {
8941
8968
  const trimmed = query.trim();
8942
8969
  if (!trimmed) return false;
@@ -8954,6 +8981,16 @@ function isShortRepairFollowUpQuery(query) {
8954
8981
  if (tokens.length > 8) return false;
8955
8982
  return SHORT_REPAIR_FOLLOW_UP_PATTERNS.some((pattern) => pattern.test(trimmed));
8956
8983
  }
8984
+ function isLowConfidenceContextFallbackQuery(query) {
8985
+ const trimmed = query.trim();
8986
+ if (!trimmed) return false;
8987
+ if (isGenericContinuationQuery(trimmed) || isShortRepairFollowUpQuery(trimmed)) return true;
8988
+ const terms = new Set(tokenizeQualityText(trimmed));
8989
+ if ((terms.has("compacted") || terms.has("compaction")) && terms.has("handoff")) return false;
8990
+ const hasContinuationRecall = /^(?:continue|resume)\b/i.test(trimmed) && (terms.has("work") || terms.has("step") || terms.has("task") || terms.has("last") || terms.has("completed"));
8991
+ 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"));
8992
+ return hasContinuationRecall || hasValidationGateRecall;
8993
+ }
8957
8994
  function isCurrentStateQuery(query) {
8958
8995
  const trimmed = query.trim();
8959
8996
  if (!trimmed) return false;
@@ -9221,7 +9258,14 @@ var Retriever = class {
9221
9258
  };
9222
9259
  fallbackTrace.push("fallback:summary");
9223
9260
  }
9224
- const memories = await this.enrichResults(current.results.slice(0, opts.topK), opts);
9261
+ const selectedResults = current.results.slice(0, opts.topK).filter((result) => {
9262
+ if (current.matchResult.confidence !== "none") return true;
9263
+ if (isLowConfidenceContextFallbackQuery(query)) {
9264
+ return (result.semanticScore ?? result.score) >= 0.5 || result.score >= 0.5;
9265
+ }
9266
+ return (result.semanticScore ?? result.score) >= 0.62 || result.score >= 0.62;
9267
+ });
9268
+ const memories = await this.enrichResults(selectedResults, opts, query);
9225
9269
  const context = this.buildContext(memories, opts.maxTokens);
9226
9270
  return {
9227
9271
  memories,
@@ -9229,7 +9273,7 @@ var Retriever = class {
9229
9273
  totalTokens: this.estimateTokens(context),
9230
9274
  context,
9231
9275
  fallbackTrace,
9232
- selectedDebug: current.results.slice(0, opts.topK).map((r) => this.debugDetailForResult(r)),
9276
+ selectedDebug: selectedResults.map((r) => this.debugDetailForResult(r)),
9233
9277
  candidateDebug: (current.candidateResults || []).slice(0, Math.max(opts.topK * 3, 20)).map((r) => this.debugDetailForResult(r)),
9234
9278
  rawQueryText: current.queryRewriteKind ? query : void 0,
9235
9279
  effectiveQueryText: current.effectiveQueryText,
@@ -9324,6 +9368,7 @@ var Retriever = class {
9324
9368
  if (isCurrentStateQuery(options.query)) {
9325
9369
  filtered = filtered.filter((result) => !isStaleOrSupersededContent(result.content));
9326
9370
  }
9371
+ filtered = filtered.filter((result) => !isLowSignalContextContent(result.content));
9327
9372
  filtered = filtered.filter(
9328
9373
  (result) => this.isGraphPathResult(result) || hasDiscriminativeTermOverlap(options.query, result.content)
9329
9374
  );
@@ -9664,7 +9709,7 @@ var Retriever = class {
9664
9709
  async retrieveRecent(limit = 100) {
9665
9710
  return this.eventStore.getRecentEvents(limit);
9666
9711
  }
9667
- async enrichResults(results, options) {
9712
+ async enrichResults(results, options, query) {
9668
9713
  const memories = [];
9669
9714
  for (const result of results) {
9670
9715
  const event = await this.eventStore.getEvent(result.eventId);
@@ -9674,13 +9719,13 @@ var Retriever = class {
9674
9719
  }
9675
9720
  let sessionContext;
9676
9721
  if (options.includeSessionContext) {
9677
- sessionContext = await this.getSessionContext(event.sessionId, event.id);
9722
+ sessionContext = await this.getSessionContext(event.sessionId, event.id, query);
9678
9723
  }
9679
9724
  memories.push({ event, score: result.score, sessionContext });
9680
9725
  }
9681
9726
  return memories;
9682
9727
  }
9683
- async getSessionContext(sessionId, eventId) {
9728
+ async getSessionContext(sessionId, eventId, query) {
9684
9729
  const sessionEvents = await this.eventStore.getSessionEvents(sessionId);
9685
9730
  const eventIndex = sessionEvents.findIndex((e) => e.id === eventId);
9686
9731
  if (eventIndex === -1) return void 0;
@@ -9688,7 +9733,9 @@ var Retriever = class {
9688
9733
  const end = Math.min(sessionEvents.length, eventIndex + 2);
9689
9734
  const contextEvents = sessionEvents.slice(start, end);
9690
9735
  if (contextEvents.length <= 1) return void 0;
9691
- return contextEvents.filter((e) => e.id !== eventId).map((e) => `[${e.eventType}]: ${e.content.slice(0, 200)}...`).join("\n");
9736
+ const suppressStaleState = isCurrentStateQuery(query);
9737
+ 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)}...`);
9738
+ return contextLines.length > 0 ? contextLines.join("\n") : void 0;
9692
9739
  }
9693
9740
  buildUnifiedContext(projectResult, sharedMemories) {
9694
9741
  let context = projectResult.context;