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.
@@ -8422,6 +8422,18 @@ var COMMAND_ARTIFACT_PATTERNS = [
8422
8422
  /<local-command-stdout>[\s\S]*?<\/local-command-stdout>/i,
8423
8423
  /<local-command-stderr>[\s\S]*?<\/local-command-stderr>/i
8424
8424
  ];
8425
+ var LOW_SIGNAL_CONTEXT_PATTERNS = [
8426
+ /<environment_context\b[\s\S]*<\/environment_context>/i,
8427
+ /<turn_aborted>/i,
8428
+ /^#\s*AGENTS\.md\s+instructions\b[\s\S]*<INSTRUCTIONS>/i,
8429
+ /^\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,
8430
+ /^\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,
8431
+ /^\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,
8432
+ /^\s*---\s*END\s+OF\s+CONTEXT\s+SUMMARY\b/i,
8433
+ /^\s*\[Your\s+active\s+task\s+list\s+was\s+preserved\s+across\s+context\s+compression\]/i,
8434
+ /^➜\s+\S+\s+git:\([^)]*\)\s+/i,
8435
+ /^\$\s+\S+/i
8436
+ ];
8425
8437
  var CONTINUATION_QUERY_PATTERNS = [
8426
8438
  /^\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,
8427
8439
  /^\s*(?:응\s*)?(?:이어서(?:\s*진행(?:해줘)?)?|계속(?:\s*해줘)?|다음\s*(?:단계|작업|추천\s*작업|추천|할\s*일)?(?:은|는)?(?:\s*(?:뭐야|진행(?:해줘)?))?\??|남은\s*(?:추가(?:로)?\s*)?(?:(?:할\s*만한\s*)?(?:작업|일)|할\s*일)?(?:은|는)?\s*(?:있어|있나|있나요|뭐야)\??|추천\s*작업(?:은|는)?(?:\s*뭐야)?\??|진행해줘)\s*$/i
@@ -8433,7 +8445,7 @@ var SHORT_REPAIR_FOLLOW_UP_PATTERNS = [
8433
8445
  var CURRENT_STATE_QUERY_PATTERNS = [
8434
8446
  /\bcurrent\b.*\b(?:state|status|deployment|blocker|pr|pull request)\b/i,
8435
8447
  /\b(?:still|as current|current)\b.*\b(?:unresolved|open|pending|not completed)\b/i,
8436
- /\b(?:old|obsolete|stale|resolved|already resolved)\b.*\b(?:current|still|unresolved|open|state|status)\b/i,
8448
+ /\b(?:old|obsolete|stale|resolved|already resolved)\b.*\b(?:current|still|unresolved|open|status)\b/i,
8437
8449
  /(?:현재|아직|이전|오래된|해결된).*(?:상태|미해결|열린|블로커|PR|풀리퀘스트)/i
8438
8450
  ];
8439
8451
  var STALE_CONTENT_PATTERNS = [
@@ -8579,6 +8591,21 @@ function isCommandArtifactQuery(query) {
8579
8591
  if (normalized.includes("command-name") || normalized.includes("command-message")) return true;
8580
8592
  return COMMAND_ARTIFACT_PATTERNS.some((pattern) => pattern.test(trimmed));
8581
8593
  }
8594
+ function isCommandArtifactContent(content) {
8595
+ const trimmed = content.trim();
8596
+ if (!trimmed) return false;
8597
+ const normalized = trimmed.toLowerCase();
8598
+ if (normalized.includes("local-command-stdout") || normalized.includes("local-command-stderr")) return true;
8599
+ if (normalized.includes("command-name") || normalized.includes("command-message")) return true;
8600
+ return COMMAND_ARTIFACT_PATTERNS.some((pattern) => pattern.test(trimmed));
8601
+ }
8602
+ function isLowSignalContextContent(content) {
8603
+ const trimmed = content.trim();
8604
+ if (!trimmed) return true;
8605
+ if (isCommandArtifactContent(trimmed)) return true;
8606
+ if (LOW_SIGNAL_CONTEXT_PATTERNS.some((pattern) => pattern.test(trimmed))) return true;
8607
+ return false;
8608
+ }
8582
8609
  function isGenericContinuationQuery(query) {
8583
8610
  const trimmed = query.trim();
8584
8611
  if (!trimmed) return false;
@@ -8596,6 +8623,16 @@ function isShortRepairFollowUpQuery(query) {
8596
8623
  if (tokens.length > 8) return false;
8597
8624
  return SHORT_REPAIR_FOLLOW_UP_PATTERNS.some((pattern) => pattern.test(trimmed));
8598
8625
  }
8626
+ function isLowConfidenceContextFallbackQuery(query) {
8627
+ const trimmed = query.trim();
8628
+ if (!trimmed) return false;
8629
+ if (isGenericContinuationQuery(trimmed) || isShortRepairFollowUpQuery(trimmed)) return true;
8630
+ const terms = new Set(tokenizeQualityText(trimmed));
8631
+ if ((terms.has("compacted") || terms.has("compaction")) && terms.has("handoff")) return false;
8632
+ const hasContinuationRecall = /^(?:continue|resume)\b/i.test(trimmed) && (terms.has("work") || terms.has("step") || terms.has("task") || terms.has("last") || terms.has("completed"));
8633
+ 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"));
8634
+ return hasContinuationRecall || hasValidationGateRecall;
8635
+ }
8599
8636
  function isCurrentStateQuery(query) {
8600
8637
  const trimmed = query.trim();
8601
8638
  if (!trimmed) return false;
@@ -8863,7 +8900,14 @@ var Retriever = class {
8863
8900
  };
8864
8901
  fallbackTrace.push("fallback:summary");
8865
8902
  }
8866
- const memories = await this.enrichResults(current.results.slice(0, opts.topK), opts);
8903
+ const selectedResults = current.results.slice(0, opts.topK).filter((result) => {
8904
+ if (current.matchResult.confidence !== "none") return true;
8905
+ if (isLowConfidenceContextFallbackQuery(query)) {
8906
+ return (result.semanticScore ?? result.score) >= 0.5 || result.score >= 0.5;
8907
+ }
8908
+ return (result.semanticScore ?? result.score) >= 0.62 || result.score >= 0.62;
8909
+ });
8910
+ const memories = await this.enrichResults(selectedResults, opts, query);
8867
8911
  const context = this.buildContext(memories, opts.maxTokens);
8868
8912
  return {
8869
8913
  memories,
@@ -8871,7 +8915,7 @@ var Retriever = class {
8871
8915
  totalTokens: this.estimateTokens(context),
8872
8916
  context,
8873
8917
  fallbackTrace,
8874
- selectedDebug: current.results.slice(0, opts.topK).map((r) => this.debugDetailForResult(r)),
8918
+ selectedDebug: selectedResults.map((r) => this.debugDetailForResult(r)),
8875
8919
  candidateDebug: (current.candidateResults || []).slice(0, Math.max(opts.topK * 3, 20)).map((r) => this.debugDetailForResult(r)),
8876
8920
  rawQueryText: current.queryRewriteKind ? query : void 0,
8877
8921
  effectiveQueryText: current.effectiveQueryText,
@@ -8966,6 +9010,7 @@ var Retriever = class {
8966
9010
  if (isCurrentStateQuery(options.query)) {
8967
9011
  filtered = filtered.filter((result) => !isStaleOrSupersededContent(result.content));
8968
9012
  }
9013
+ filtered = filtered.filter((result) => !isLowSignalContextContent(result.content));
8969
9014
  filtered = filtered.filter(
8970
9015
  (result) => this.isGraphPathResult(result) || hasDiscriminativeTermOverlap(options.query, result.content)
8971
9016
  );
@@ -9306,7 +9351,7 @@ var Retriever = class {
9306
9351
  async retrieveRecent(limit = 100) {
9307
9352
  return this.eventStore.getRecentEvents(limit);
9308
9353
  }
9309
- async enrichResults(results, options) {
9354
+ async enrichResults(results, options, query) {
9310
9355
  const memories = [];
9311
9356
  for (const result of results) {
9312
9357
  const event = await this.eventStore.getEvent(result.eventId);
@@ -9316,13 +9361,13 @@ var Retriever = class {
9316
9361
  }
9317
9362
  let sessionContext;
9318
9363
  if (options.includeSessionContext) {
9319
- sessionContext = await this.getSessionContext(event.sessionId, event.id);
9364
+ sessionContext = await this.getSessionContext(event.sessionId, event.id, query);
9320
9365
  }
9321
9366
  memories.push({ event, score: result.score, sessionContext });
9322
9367
  }
9323
9368
  return memories;
9324
9369
  }
9325
- async getSessionContext(sessionId, eventId) {
9370
+ async getSessionContext(sessionId, eventId, query) {
9326
9371
  const sessionEvents = await this.eventStore.getSessionEvents(sessionId);
9327
9372
  const eventIndex = sessionEvents.findIndex((e) => e.id === eventId);
9328
9373
  if (eventIndex === -1) return void 0;
@@ -9330,7 +9375,9 @@ var Retriever = class {
9330
9375
  const end = Math.min(sessionEvents.length, eventIndex + 2);
9331
9376
  const contextEvents = sessionEvents.slice(start, end);
9332
9377
  if (contextEvents.length <= 1) return void 0;
9333
- return contextEvents.filter((e) => e.id !== eventId).map((e) => `[${e.eventType}]: ${e.content.slice(0, 200)}...`).join("\n");
9378
+ const suppressStaleState = isCurrentStateQuery(query);
9379
+ 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)}...`);
9380
+ return contextLines.length > 0 ? contextLines.join("\n") : void 0;
9334
9381
  }
9335
9382
  buildUnifiedContext(projectResult, sharedMemories) {
9336
9383
  let context = projectResult.context;