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.
@@ -8460,6 +8460,18 @@ var COMMAND_ARTIFACT_PATTERNS = [
8460
8460
  /<local-command-stdout>[\s\S]*?<\/local-command-stdout>/i,
8461
8461
  /<local-command-stderr>[\s\S]*?<\/local-command-stderr>/i
8462
8462
  ];
8463
+ var LOW_SIGNAL_CONTEXT_PATTERNS = [
8464
+ /<environment_context\b[\s\S]*<\/environment_context>/i,
8465
+ /<turn_aborted>/i,
8466
+ /^#\s*AGENTS\.md\s+instructions\b[\s\S]*<INSTRUCTIONS>/i,
8467
+ /^\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,
8468
+ /^\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,
8469
+ /^\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,
8470
+ /^\s*---\s*END\s+OF\s+CONTEXT\s+SUMMARY\b/i,
8471
+ /^\s*\[Your\s+active\s+task\s+list\s+was\s+preserved\s+across\s+context\s+compression\]/i,
8472
+ /^➜\s+\S+\s+git:\([^)]*\)\s+/i,
8473
+ /^\$\s+\S+/i
8474
+ ];
8463
8475
  var CONTINUATION_QUERY_PATTERNS = [
8464
8476
  /^\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,
8465
8477
  /^\s*(?:응\s*)?(?:이어서(?:\s*진행(?:해줘)?)?|계속(?:\s*해줘)?|다음\s*(?:단계|작업|추천\s*작업|추천|할\s*일)?(?:은|는)?(?:\s*(?:뭐야|진행(?:해줘)?))?\??|남은\s*(?:추가(?:로)?\s*)?(?:(?:할\s*만한\s*)?(?:작업|일)|할\s*일)?(?:은|는)?\s*(?:있어|있나|있나요|뭐야)\??|추천\s*작업(?:은|는)?(?:\s*뭐야)?\??|진행해줘)\s*$/i
@@ -8471,7 +8483,7 @@ var SHORT_REPAIR_FOLLOW_UP_PATTERNS = [
8471
8483
  var CURRENT_STATE_QUERY_PATTERNS = [
8472
8484
  /\bcurrent\b.*\b(?:state|status|deployment|blocker|pr|pull request)\b/i,
8473
8485
  /\b(?:still|as current|current)\b.*\b(?:unresolved|open|pending|not completed)\b/i,
8474
- /\b(?:old|obsolete|stale|resolved|already resolved)\b.*\b(?:current|still|unresolved|open|state|status)\b/i,
8486
+ /\b(?:old|obsolete|stale|resolved|already resolved)\b.*\b(?:current|still|unresolved|open|status)\b/i,
8475
8487
  /(?:현재|아직|이전|오래된|해결된).*(?:상태|미해결|열린|블로커|PR|풀리퀘스트)/i
8476
8488
  ];
8477
8489
  var STALE_CONTENT_PATTERNS = [
@@ -8617,6 +8629,21 @@ function isCommandArtifactQuery(query) {
8617
8629
  if (normalized.includes("command-name") || normalized.includes("command-message")) return true;
8618
8630
  return COMMAND_ARTIFACT_PATTERNS.some((pattern) => pattern.test(trimmed));
8619
8631
  }
8632
+ function isCommandArtifactContent(content) {
8633
+ const trimmed = content.trim();
8634
+ if (!trimmed) return false;
8635
+ const normalized = trimmed.toLowerCase();
8636
+ if (normalized.includes("local-command-stdout") || normalized.includes("local-command-stderr")) return true;
8637
+ if (normalized.includes("command-name") || normalized.includes("command-message")) return true;
8638
+ return COMMAND_ARTIFACT_PATTERNS.some((pattern) => pattern.test(trimmed));
8639
+ }
8640
+ function isLowSignalContextContent(content) {
8641
+ const trimmed = content.trim();
8642
+ if (!trimmed) return true;
8643
+ if (isCommandArtifactContent(trimmed)) return true;
8644
+ if (LOW_SIGNAL_CONTEXT_PATTERNS.some((pattern) => pattern.test(trimmed))) return true;
8645
+ return false;
8646
+ }
8620
8647
  function isGenericContinuationQuery(query) {
8621
8648
  const trimmed = query.trim();
8622
8649
  if (!trimmed) return false;
@@ -8634,6 +8661,16 @@ function isShortRepairFollowUpQuery(query) {
8634
8661
  if (tokens.length > 8) return false;
8635
8662
  return SHORT_REPAIR_FOLLOW_UP_PATTERNS.some((pattern) => pattern.test(trimmed));
8636
8663
  }
8664
+ function isLowConfidenceContextFallbackQuery(query) {
8665
+ const trimmed = query.trim();
8666
+ if (!trimmed) return false;
8667
+ if (isGenericContinuationQuery(trimmed) || isShortRepairFollowUpQuery(trimmed)) return true;
8668
+ const terms = new Set(tokenizeQualityText(trimmed));
8669
+ if ((terms.has("compacted") || terms.has("compaction")) && terms.has("handoff")) return false;
8670
+ const hasContinuationRecall = /^(?:continue|resume)\b/i.test(trimmed) && (terms.has("work") || terms.has("step") || terms.has("task") || terms.has("last") || terms.has("completed"));
8671
+ 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"));
8672
+ return hasContinuationRecall || hasValidationGateRecall;
8673
+ }
8637
8674
  function isCurrentStateQuery(query) {
8638
8675
  const trimmed = query.trim();
8639
8676
  if (!trimmed) return false;
@@ -8901,7 +8938,14 @@ var Retriever = class {
8901
8938
  };
8902
8939
  fallbackTrace.push("fallback:summary");
8903
8940
  }
8904
- const memories = await this.enrichResults(current.results.slice(0, opts.topK), opts);
8941
+ const selectedResults = current.results.slice(0, opts.topK).filter((result) => {
8942
+ if (current.matchResult.confidence !== "none") return true;
8943
+ if (isLowConfidenceContextFallbackQuery(query)) {
8944
+ return (result.semanticScore ?? result.score) >= 0.5 || result.score >= 0.5;
8945
+ }
8946
+ return (result.semanticScore ?? result.score) >= 0.62 || result.score >= 0.62;
8947
+ });
8948
+ const memories = await this.enrichResults(selectedResults, opts, query);
8905
8949
  const context = this.buildContext(memories, opts.maxTokens);
8906
8950
  return {
8907
8951
  memories,
@@ -8909,7 +8953,7 @@ var Retriever = class {
8909
8953
  totalTokens: this.estimateTokens(context),
8910
8954
  context,
8911
8955
  fallbackTrace,
8912
- selectedDebug: current.results.slice(0, opts.topK).map((r) => this.debugDetailForResult(r)),
8956
+ selectedDebug: selectedResults.map((r) => this.debugDetailForResult(r)),
8913
8957
  candidateDebug: (current.candidateResults || []).slice(0, Math.max(opts.topK * 3, 20)).map((r) => this.debugDetailForResult(r)),
8914
8958
  rawQueryText: current.queryRewriteKind ? query : void 0,
8915
8959
  effectiveQueryText: current.effectiveQueryText,
@@ -9004,6 +9048,7 @@ var Retriever = class {
9004
9048
  if (isCurrentStateQuery(options.query)) {
9005
9049
  filtered = filtered.filter((result) => !isStaleOrSupersededContent(result.content));
9006
9050
  }
9051
+ filtered = filtered.filter((result) => !isLowSignalContextContent(result.content));
9007
9052
  filtered = filtered.filter(
9008
9053
  (result) => this.isGraphPathResult(result) || hasDiscriminativeTermOverlap(options.query, result.content)
9009
9054
  );
@@ -9344,7 +9389,7 @@ var Retriever = class {
9344
9389
  async retrieveRecent(limit = 100) {
9345
9390
  return this.eventStore.getRecentEvents(limit);
9346
9391
  }
9347
- async enrichResults(results, options) {
9392
+ async enrichResults(results, options, query) {
9348
9393
  const memories = [];
9349
9394
  for (const result of results) {
9350
9395
  const event = await this.eventStore.getEvent(result.eventId);
@@ -9354,13 +9399,13 @@ var Retriever = class {
9354
9399
  }
9355
9400
  let sessionContext;
9356
9401
  if (options.includeSessionContext) {
9357
- sessionContext = await this.getSessionContext(event.sessionId, event.id);
9402
+ sessionContext = await this.getSessionContext(event.sessionId, event.id, query);
9358
9403
  }
9359
9404
  memories.push({ event, score: result.score, sessionContext });
9360
9405
  }
9361
9406
  return memories;
9362
9407
  }
9363
- async getSessionContext(sessionId, eventId) {
9408
+ async getSessionContext(sessionId, eventId, query) {
9364
9409
  const sessionEvents = await this.eventStore.getSessionEvents(sessionId);
9365
9410
  const eventIndex = sessionEvents.findIndex((e) => e.id === eventId);
9366
9411
  if (eventIndex === -1) return void 0;
@@ -9368,7 +9413,9 @@ var Retriever = class {
9368
9413
  const end = Math.min(sessionEvents.length, eventIndex + 2);
9369
9414
  const contextEvents = sessionEvents.slice(start, end);
9370
9415
  if (contextEvents.length <= 1) return void 0;
9371
- return contextEvents.filter((e) => e.id !== eventId).map((e) => `[${e.eventType}]: ${e.content.slice(0, 200)}...`).join("\n");
9416
+ const suppressStaleState = isCurrentStateQuery(query);
9417
+ 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)}...`);
9418
+ return contextLines.length > 0 ? contextLines.join("\n") : void 0;
9372
9419
  }
9373
9420
  buildUnifiedContext(projectResult, sharedMemories) {
9374
9421
  let context = projectResult.context;