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.
@@ -8448,6 +8448,18 @@ var COMMAND_ARTIFACT_PATTERNS = [
8448
8448
  /<local-command-stdout>[\s\S]*?<\/local-command-stdout>/i,
8449
8449
  /<local-command-stderr>[\s\S]*?<\/local-command-stderr>/i
8450
8450
  ];
8451
+ var LOW_SIGNAL_CONTEXT_PATTERNS = [
8452
+ /<environment_context\b[\s\S]*<\/environment_context>/i,
8453
+ /<turn_aborted>/i,
8454
+ /^#\s*AGENTS\.md\s+instructions\b[\s\S]*<INSTRUCTIONS>/i,
8455
+ /^\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,
8456
+ /^\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,
8457
+ /^\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,
8458
+ /^\s*---\s*END\s+OF\s+CONTEXT\s+SUMMARY\b/i,
8459
+ /^\s*\[Your\s+active\s+task\s+list\s+was\s+preserved\s+across\s+context\s+compression\]/i,
8460
+ /^➜\s+\S+\s+git:\([^)]*\)\s+/i,
8461
+ /^\$\s+\S+/i
8462
+ ];
8451
8463
  var CONTINUATION_QUERY_PATTERNS = [
8452
8464
  /^\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,
8453
8465
  /^\s*(?:응\s*)?(?:이어서(?:\s*진행(?:해줘)?)?|계속(?:\s*해줘)?|다음\s*(?:단계|작업|추천\s*작업|추천|할\s*일)?(?:은|는)?(?:\s*(?:뭐야|진행(?:해줘)?))?\??|남은\s*(?:추가(?:로)?\s*)?(?:(?:할\s*만한\s*)?(?:작업|일)|할\s*일)?(?:은|는)?\s*(?:있어|있나|있나요|뭐야)\??|추천\s*작업(?:은|는)?(?:\s*뭐야)?\??|진행해줘)\s*$/i
@@ -8459,7 +8471,7 @@ var SHORT_REPAIR_FOLLOW_UP_PATTERNS = [
8459
8471
  var CURRENT_STATE_QUERY_PATTERNS = [
8460
8472
  /\bcurrent\b.*\b(?:state|status|deployment|blocker|pr|pull request)\b/i,
8461
8473
  /\b(?:still|as current|current)\b.*\b(?:unresolved|open|pending|not completed)\b/i,
8462
- /\b(?:old|obsolete|stale|resolved|already resolved)\b.*\b(?:current|still|unresolved|open|state|status)\b/i,
8474
+ /\b(?:old|obsolete|stale|resolved|already resolved)\b.*\b(?:current|still|unresolved|open|status)\b/i,
8463
8475
  /(?:현재|아직|이전|오래된|해결된).*(?:상태|미해결|열린|블로커|PR|풀리퀘스트)/i
8464
8476
  ];
8465
8477
  var STALE_CONTENT_PATTERNS = [
@@ -8605,6 +8617,21 @@ function isCommandArtifactQuery(query) {
8605
8617
  if (normalized.includes("command-name") || normalized.includes("command-message")) return true;
8606
8618
  return COMMAND_ARTIFACT_PATTERNS.some((pattern) => pattern.test(trimmed));
8607
8619
  }
8620
+ function isCommandArtifactContent(content) {
8621
+ const trimmed = content.trim();
8622
+ if (!trimmed) return false;
8623
+ const normalized = trimmed.toLowerCase();
8624
+ if (normalized.includes("local-command-stdout") || normalized.includes("local-command-stderr")) return true;
8625
+ if (normalized.includes("command-name") || normalized.includes("command-message")) return true;
8626
+ return COMMAND_ARTIFACT_PATTERNS.some((pattern) => pattern.test(trimmed));
8627
+ }
8628
+ function isLowSignalContextContent(content) {
8629
+ const trimmed = content.trim();
8630
+ if (!trimmed) return true;
8631
+ if (isCommandArtifactContent(trimmed)) return true;
8632
+ if (LOW_SIGNAL_CONTEXT_PATTERNS.some((pattern) => pattern.test(trimmed))) return true;
8633
+ return false;
8634
+ }
8608
8635
  function isGenericContinuationQuery(query) {
8609
8636
  const trimmed = query.trim();
8610
8637
  if (!trimmed) return false;
@@ -8622,6 +8649,16 @@ function isShortRepairFollowUpQuery(query) {
8622
8649
  if (tokens.length > 8) return false;
8623
8650
  return SHORT_REPAIR_FOLLOW_UP_PATTERNS.some((pattern) => pattern.test(trimmed));
8624
8651
  }
8652
+ function isLowConfidenceContextFallbackQuery(query) {
8653
+ const trimmed = query.trim();
8654
+ if (!trimmed) return false;
8655
+ if (isGenericContinuationQuery(trimmed) || isShortRepairFollowUpQuery(trimmed)) return true;
8656
+ const terms = new Set(tokenizeQualityText(trimmed));
8657
+ if ((terms.has("compacted") || terms.has("compaction")) && terms.has("handoff")) return false;
8658
+ const hasContinuationRecall = /^(?:continue|resume)\b/i.test(trimmed) && (terms.has("work") || terms.has("step") || terms.has("task") || terms.has("last") || terms.has("completed"));
8659
+ 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"));
8660
+ return hasContinuationRecall || hasValidationGateRecall;
8661
+ }
8625
8662
  function isCurrentStateQuery(query) {
8626
8663
  const trimmed = query.trim();
8627
8664
  if (!trimmed) return false;
@@ -8889,7 +8926,14 @@ var Retriever = class {
8889
8926
  };
8890
8927
  fallbackTrace.push("fallback:summary");
8891
8928
  }
8892
- const memories = await this.enrichResults(current.results.slice(0, opts.topK), opts);
8929
+ const selectedResults = current.results.slice(0, opts.topK).filter((result) => {
8930
+ if (current.matchResult.confidence !== "none") return true;
8931
+ if (isLowConfidenceContextFallbackQuery(query)) {
8932
+ return (result.semanticScore ?? result.score) >= 0.5 || result.score >= 0.5;
8933
+ }
8934
+ return (result.semanticScore ?? result.score) >= 0.62 || result.score >= 0.62;
8935
+ });
8936
+ const memories = await this.enrichResults(selectedResults, opts, query);
8893
8937
  const context = this.buildContext(memories, opts.maxTokens);
8894
8938
  return {
8895
8939
  memories,
@@ -8897,7 +8941,7 @@ var Retriever = class {
8897
8941
  totalTokens: this.estimateTokens(context),
8898
8942
  context,
8899
8943
  fallbackTrace,
8900
- selectedDebug: current.results.slice(0, opts.topK).map((r) => this.debugDetailForResult(r)),
8944
+ selectedDebug: selectedResults.map((r) => this.debugDetailForResult(r)),
8901
8945
  candidateDebug: (current.candidateResults || []).slice(0, Math.max(opts.topK * 3, 20)).map((r) => this.debugDetailForResult(r)),
8902
8946
  rawQueryText: current.queryRewriteKind ? query : void 0,
8903
8947
  effectiveQueryText: current.effectiveQueryText,
@@ -8992,6 +9036,7 @@ var Retriever = class {
8992
9036
  if (isCurrentStateQuery(options.query)) {
8993
9037
  filtered = filtered.filter((result) => !isStaleOrSupersededContent(result.content));
8994
9038
  }
9039
+ filtered = filtered.filter((result) => !isLowSignalContextContent(result.content));
8995
9040
  filtered = filtered.filter(
8996
9041
  (result) => this.isGraphPathResult(result) || hasDiscriminativeTermOverlap(options.query, result.content)
8997
9042
  );
@@ -9332,7 +9377,7 @@ var Retriever = class {
9332
9377
  async retrieveRecent(limit = 100) {
9333
9378
  return this.eventStore.getRecentEvents(limit);
9334
9379
  }
9335
- async enrichResults(results, options) {
9380
+ async enrichResults(results, options, query) {
9336
9381
  const memories = [];
9337
9382
  for (const result of results) {
9338
9383
  const event = await this.eventStore.getEvent(result.eventId);
@@ -9342,13 +9387,13 @@ var Retriever = class {
9342
9387
  }
9343
9388
  let sessionContext;
9344
9389
  if (options.includeSessionContext) {
9345
- sessionContext = await this.getSessionContext(event.sessionId, event.id);
9390
+ sessionContext = await this.getSessionContext(event.sessionId, event.id, query);
9346
9391
  }
9347
9392
  memories.push({ event, score: result.score, sessionContext });
9348
9393
  }
9349
9394
  return memories;
9350
9395
  }
9351
- async getSessionContext(sessionId, eventId) {
9396
+ async getSessionContext(sessionId, eventId, query) {
9352
9397
  const sessionEvents = await this.eventStore.getSessionEvents(sessionId);
9353
9398
  const eventIndex = sessionEvents.findIndex((e) => e.id === eventId);
9354
9399
  if (eventIndex === -1) return void 0;
@@ -9356,7 +9401,9 @@ var Retriever = class {
9356
9401
  const end = Math.min(sessionEvents.length, eventIndex + 2);
9357
9402
  const contextEvents = sessionEvents.slice(start, end);
9358
9403
  if (contextEvents.length <= 1) return void 0;
9359
- return contextEvents.filter((e) => e.id !== eventId).map((e) => `[${e.eventType}]: ${e.content.slice(0, 200)}...`).join("\n");
9404
+ const suppressStaleState = isCurrentStateQuery(query);
9405
+ 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)}...`);
9406
+ return contextLines.length > 0 ? contextLines.join("\n") : void 0;
9360
9407
  }
9361
9408
  buildUnifiedContext(projectResult, sharedMemories) {
9362
9409
  let context = projectResult.context;