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