@agentmemory/agentmemory 0.8.8 → 0.8.10

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.
@@ -1,5 +1,5 @@
1
1
  import { a as jaccardSimilarity, i as generateId, n as STREAM, r as fingerprintId, t as KV } from "./cli.mjs";
2
- import { a as getEnvVar, c as isConsolidationEnabled, d as loadConfig, f as loadEmbeddingConfig, h as loadTeamConfig, i as getConsolidationDecayDays, l as isGraphExtractionEnabled, m as loadSnapshotConfig, n as VERSION, p as loadFallbackConfig, r as detectEmbeddingProvider, s as isAutoCompressEnabled, t as getVisibleTools, u as loadClaudeBridgeConfig } from "./tools-registry-BuDo4gKj.mjs";
2
+ import { a as getEnvVar, c as isConsolidationEnabled, d as loadClaudeBridgeConfig, f as loadConfig, g as loadTeamConfig, h as loadSnapshotConfig, i as getConsolidationDecayDays, l as isContextInjectionEnabled, m as loadFallbackConfig, n as VERSION, p as loadEmbeddingConfig, r as detectEmbeddingProvider, s as isAutoCompressEnabled, t as getVisibleTools, u as isGraphExtractionEnabled } from "./tools-registry-DXnvw9ZI.mjs";
3
3
  import { execFile } from "node:child_process";
4
4
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
5
5
  import { dirname, join, resolve, sep } from "node:path";
@@ -4016,7 +4016,9 @@ function registerExportImportFunction(sdk, kv) {
4016
4016
  "0.8.5",
4017
4017
  "0.8.6",
4018
4018
  "0.8.7",
4019
- "0.8.8"
4019
+ "0.8.8",
4020
+ "0.8.9",
4021
+ "0.8.10"
4020
4022
  ]).has(importData.version)) return {
4021
4023
  success: false,
4022
4024
  error: `Unsupported export version: ${importData.version}`
@@ -9881,6 +9883,9 @@ function registerRetentionFunctions(sdk, kv) {
9881
9883
  }
9882
9884
  const scores = [];
9883
9885
  const computeDecay = (createdAt) => Math.exp(-config.lambda * ((Date.now() - new Date(createdAt).getTime()) / (1e3 * 60 * 60 * 24)));
9886
+ const pendingWrites = [];
9887
+ let episodicScored = 0;
9888
+ let semanticScored = 0;
9884
9889
  for (const mem of memories) {
9885
9890
  if (!mem.isLatest) continue;
9886
9891
  const log = logsById.get(mem.id) ?? emptyAccessLog(mem.id);
@@ -9890,6 +9895,7 @@ function registerRetentionFunctions(sdk, kv) {
9890
9895
  const score = Math.min(1, salience * temporalDecay + reinforcementBoost);
9891
9896
  const entry = {
9892
9897
  memoryId: mem.id,
9898
+ source: "episodic",
9893
9899
  score,
9894
9900
  salience,
9895
9901
  temporalDecay,
@@ -9898,7 +9904,8 @@ function registerRetentionFunctions(sdk, kv) {
9898
9904
  accessCount: log.count
9899
9905
  };
9900
9906
  scores.push(entry);
9901
- await kv.set(KV.retentionScores, mem.id, entry);
9907
+ pendingWrites.push([mem.id, entry]);
9908
+ episodicScored++;
9902
9909
  }
9903
9910
  for (const sem of semanticMems) {
9904
9911
  const log = logsById.get(sem.id) ?? emptyAccessLog(sem.id);
@@ -9921,6 +9928,7 @@ function registerRetentionFunctions(sdk, kv) {
9921
9928
  const score = Math.min(1, salience * temporalDecay + reinforcementBoost);
9922
9929
  const entry = {
9923
9930
  memoryId: sem.id,
9931
+ source: "semantic",
9924
9932
  score,
9925
9933
  salience,
9926
9934
  temporalDecay,
@@ -9929,8 +9937,10 @@ function registerRetentionFunctions(sdk, kv) {
9929
9937
  accessCount: effectiveCount
9930
9938
  };
9931
9939
  scores.push(entry);
9932
- await kv.set(KV.retentionScores, sem.id, entry);
9940
+ pendingWrites.push([sem.id, entry]);
9941
+ semanticScored++;
9933
9942
  }
9943
+ await Promise.all(pendingWrites.map(([id, entry]) => kv.set(KV.retentionScores, id, entry)));
9934
9944
  scores.sort((a, b) => b.score - a.score);
9935
9945
  const tiers = {
9936
9946
  hot: scores.filter((s) => s.score >= config.tierThresholds.hot).length,
@@ -9942,6 +9952,13 @@ function registerRetentionFunctions(sdk, kv) {
9942
9952
  total: scores.length,
9943
9953
  ...tiers
9944
9954
  });
9955
+ if (scores.length > 0) await recordAudit(kv, "retention_score", "mem::retention-score", [], {
9956
+ total: scores.length,
9957
+ episodic: episodicScored,
9958
+ semantic: semanticScored,
9959
+ tiers,
9960
+ config
9961
+ });
9945
9962
  return {
9946
9963
  success: true,
9947
9964
  total: scores.length,
@@ -9967,21 +9984,53 @@ function registerRetentionFunctions(sdk, kv) {
9967
9984
  }))
9968
9985
  };
9969
9986
  let evicted = 0;
9987
+ let evictedEpisodic = 0;
9988
+ let evictedSemantic = 0;
9989
+ const evictedIds = [];
9970
9990
  for (const candidate of candidates) try {
9971
- await kv.delete(KV.memories, candidate.memoryId);
9991
+ let scope;
9992
+ let resolvedSource;
9993
+ if (candidate.source === "semantic") {
9994
+ scope = KV.semantic;
9995
+ resolvedSource = "semantic";
9996
+ } else if (candidate.source === "episodic") {
9997
+ scope = KV.memories;
9998
+ resolvedSource = "episodic";
9999
+ } else if (await kv.get(KV.memories, candidate.memoryId) !== null) {
10000
+ scope = KV.memories;
10001
+ resolvedSource = "episodic";
10002
+ } else {
10003
+ scope = KV.semantic;
10004
+ resolvedSource = "semantic";
10005
+ }
10006
+ await kv.delete(scope, candidate.memoryId);
9972
10007
  await kv.delete(KV.retentionScores, candidate.memoryId);
9973
10008
  await deleteAccessLog(kv, candidate.memoryId);
9974
10009
  evicted++;
10010
+ evictedIds.push(candidate.memoryId);
10011
+ if (resolvedSource === "semantic") evictedSemantic++;
10012
+ else evictedEpisodic++;
9975
10013
  } catch {
9976
10014
  continue;
9977
10015
  }
10016
+ if (evicted > 0) await recordAudit(kv, "delete", "mem::retention-evict", evictedIds, {
10017
+ threshold,
10018
+ evicted,
10019
+ evictedEpisodic,
10020
+ evictedSemantic,
10021
+ reason: "retention score below threshold"
10022
+ });
9978
10023
  ctx.logger.info("Retention-based eviction complete", {
9979
10024
  evicted,
10025
+ evictedEpisodic,
10026
+ evictedSemantic,
9980
10027
  threshold
9981
10028
  });
9982
10029
  return {
9983
10030
  success: true,
9984
- evicted
10031
+ evicted,
10032
+ evictedEpisodic,
10033
+ evictedSemantic
9985
10034
  };
9986
10035
  });
9987
10036
  }
@@ -13935,6 +13984,8 @@ async function main() {
13935
13984
  console.log(`[agentmemory] Consolidation pipeline: registered (CONSOLIDATION_ENABLED=${isConsolidationEnabled() ? "true" : "false"})`);
13936
13985
  if (isAutoCompressEnabled()) console.log(`[agentmemory] WARNING: AGENTMEMORY_AUTO_COMPRESS=true — every PostToolUse observation will be sent to your LLM provider for compression. This spends API tokens proportional to your session tool-use frequency (see #138). Set AGENTMEMORY_AUTO_COMPRESS=false to disable.`);
13937
13986
  else console.log(`[agentmemory] Auto-compress: OFF (default, #138) — observations indexed via zero-LLM synthetic compression. Set AGENTMEMORY_AUTO_COMPRESS=true to opt-in to LLM-powered summaries (uses your API key).`);
13987
+ if (isContextInjectionEnabled()) console.log(`[agentmemory] WARNING: AGENTMEMORY_INJECT_CONTEXT=true — the PreToolUse and SessionStart hooks will inject up to ~4000 chars of memory context into every tool turn. On Claude Pro this burns session tokens proportional to your tool-call frequency (see #143). Set AGENTMEMORY_INJECT_CONTEXT=false to disable.`);
13988
+ else console.log(`[agentmemory] Context injection: OFF (default, #143) — hooks capture observations but do not inject context into Claude Code's conversation. Set AGENTMEMORY_INJECT_CONTEXT=true to opt-in (warning: expect your Claude Pro allocation to drain faster).`);
13938
13989
  const teamConfig = loadTeamConfig();
13939
13990
  if (teamConfig) {
13940
13991
  registerTeamFunction(sdk, kv, teamConfig);
@@ -14060,4 +14111,4 @@ main().catch((err) => {
14060
14111
 
14061
14112
  //#endregion
14062
14113
  export { };
14063
- //# sourceMappingURL=src-CneY0pgf.mjs.map
14114
+ //# sourceMappingURL=src-65nK6f5B.mjs.map