@xdarkicex/openclaw-memory-libravdb 1.8.7 → 1.8.9

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.
@@ -11,7 +11,7 @@ const DEFAULT_COMPACTION_THRESHOLD_FRACTION = 0.8;
11
11
  const STRUCTURED_MARKER_RE = /\b[A-Z][A-Z0-9]*(?:_[A-Z0-9]+){2,}_\d{6,}\b/g;
12
12
  const DISTINCTIVE_IDENTIFIER_RE = /\b([A-Za-z][A-Za-z0-9]*(?:[_-][A-Za-z0-9]+){1,})\b/g;
13
13
  const QUOTED_PHRASE_RE = /"([^"]{4,})"|'([^']{4,})'/g;
14
- const EXACT_RECALL_SEARCH_K = 32;
14
+ const EXACT_RECALL_SEARCH_K = 10;
15
15
  const EXACT_RECALL_MAX_TOKENS = 4;
16
16
  const RESERVED_CURRENT_TURN_TOKENS = 150;
17
17
  const AFTER_TURN_INGEST_MAX_TOKENS = 2048;
@@ -1265,6 +1265,13 @@ const SUBAGENT_BUDGET_MAX = 200;
1265
1265
  function subagentKey(sessionKey) {
1266
1266
  return sessionKey.trim();
1267
1267
  }
1268
+ function normalizeSubagentTokenBudget(value) {
1269
+ if (typeof value !== "number")
1270
+ return 8000;
1271
+ if (!Number.isFinite(value) || value < 0)
1272
+ return 8000;
1273
+ return Math.floor(value);
1274
+ }
1268
1275
  // consumeSubagentBudget deducts tokens from the subagent's budget.
1269
1276
  // Returns the granted budget, or -1 if no budget exists (not a subagent).
1270
1277
  export function consumeSubagentBudget(sessionKey, tokens) {
@@ -1283,7 +1290,14 @@ export function consumeSubagentBudget(sessionKey, tokens) {
1283
1290
  const budget = subagentBudgets.get(subagentKey(sessionKey));
1284
1291
  if (!budget)
1285
1292
  return -1; // not a subagent — no budget cap
1286
- const granted = Math.min(tokens, budget.remaining);
1293
+ const requested = Math.floor(tokens);
1294
+ if (!Number.isFinite(requested) || requested <= 0)
1295
+ return 0;
1296
+ if (!Number.isFinite(budget.remaining) || budget.remaining <= 0) {
1297
+ budget.remaining = 0;
1298
+ return 0;
1299
+ }
1300
+ const granted = Math.min(requested, budget.remaining);
1287
1301
  budget.remaining = Math.max(0, budget.remaining - granted);
1288
1302
  return granted;
1289
1303
  }
@@ -1628,15 +1642,20 @@ export function buildContextEngineFactory(runtime, cfg, logger = console) {
1628
1642
  }
1629
1643
  async function injectContinuityContext(params) {
1630
1644
  try {
1645
+ // Use a natural-language query that semantically matches the
1646
+ // pointer record text ("Previous session continuity — ...").
1647
+ // Fetch enough results so the exact ID match isn't crowded out
1648
+ // by stronger semantic hits in the user collection.
1631
1649
  const continuityHits = await params.client.searchTextCollections({
1632
1650
  collections: [resolveUserCollection(params.userId)],
1633
- text: "__session_continuity__",
1634
- k: 1,
1651
+ text: "previous session context continuity",
1652
+ k: 8,
1635
1653
  excludeByCollection: {},
1636
1654
  });
1637
1655
  const continuityHit = continuityHits.results?.find((r) => r.id === "__session_continuity__");
1638
- if (!continuityHit)
1639
- return null;
1656
+ if (!continuityHit) {
1657
+ return '<continuity_context>\nNo prior session context available. Use memory_search to recall previous conversations.\n</continuity_context>';
1658
+ }
1640
1659
  let meta = {};
1641
1660
  if (continuityHit.metadataJson && continuityHit.metadataJson.length > 0) {
1642
1661
  try {
@@ -1645,15 +1664,17 @@ export function buildContextEngineFactory(runtime, cfg, logger = console) {
1645
1664
  catch { /* metadata parse failed, use empty */ }
1646
1665
  }
1647
1666
  const summaryId = meta.summary_id;
1648
- if (!summaryId)
1649
- return null;
1667
+ if (!summaryId) {
1668
+ const sid = meta.session_id ?? params.sessionId;
1669
+ return '<continuity_context>\nThe previous session (' + sid + ') was not compacted. Use memory_search with queries about what was discussed to recall context.\n</continuity_context>';
1670
+ }
1650
1671
  const expanded = await params.client.expandSummary({
1651
1672
  sessionId: meta.session_id ?? params.sessionId,
1652
1673
  summaryId,
1653
1674
  maxDepth: 2,
1654
1675
  });
1655
1676
  if (!expanded.text)
1656
- return null;
1677
+ return '<continuity_context>\nFailed to expand prior session summary. Use memory_search to recall previous conversations.\n</continuity_context>';
1657
1678
  return '<continuity_context>\nThe following is a summary of the previous session. Use it for context about what was discussed before the reset.\n' + expanded.text + '\n</continuity_context>';
1658
1679
  }
1659
1680
  catch {
@@ -2104,9 +2125,7 @@ export function buildContextEngineFactory(runtime, cfg, logger = console) {
2104
2125
  // Grant the subagent a token budget for memory expansion.
2105
2126
  // Default 8000 tokens — enough for a focused expansion,
2106
2127
  // small enough to prevent context window destruction.
2107
- const budget = typeof cfg.subagentTokenBudget === "number"
2108
- ? cfg.subagentTokenBudget
2109
- : 8000;
2128
+ const budget = normalizeSubagentTokenBudget(cfg.subagentTokenBudget);
2110
2129
  const seconds = typeof params.ttlMs === "number" && params.ttlMs > 0
2111
2130
  ? Math.ceil(params.ttlMs / 1000)
2112
2131
  : 120;
package/dist/index.js CHANGED
@@ -26761,7 +26761,7 @@ var DEFAULT_COMPACTION_THRESHOLD_FRACTION = 0.8;
26761
26761
  var STRUCTURED_MARKER_RE = /\b[A-Z][A-Z0-9]*(?:_[A-Z0-9]+){2,}_\d{6,}\b/g;
26762
26762
  var DISTINCTIVE_IDENTIFIER_RE = /\b([A-Za-z][A-Za-z0-9]*(?:[_-][A-Za-z0-9]+){1,})\b/g;
26763
26763
  var QUOTED_PHRASE_RE = /"([^"]{4,})"|'([^']{4,})'/g;
26764
- var EXACT_RECALL_SEARCH_K = 32;
26764
+ var EXACT_RECALL_SEARCH_K = 10;
26765
26765
  var EXACT_RECALL_MAX_TOKENS = 4;
26766
26766
  var RESERVED_CURRENT_TURN_TOKENS = 150;
26767
26767
  var AFTER_TURN_INGEST_MAX_TOKENS = 2048;
@@ -27807,6 +27807,11 @@ var SUBAGENT_BUDGET_MAX = 200;
27807
27807
  function subagentKey(sessionKey) {
27808
27808
  return sessionKey.trim();
27809
27809
  }
27810
+ function normalizeSubagentTokenBudget(value) {
27811
+ if (typeof value !== "number") return 8e3;
27812
+ if (!Number.isFinite(value) || value < 0) return 8e3;
27813
+ return Math.floor(value);
27814
+ }
27810
27815
  function consumeSubagentBudget(sessionKey, tokens) {
27811
27816
  const now = Date.now();
27812
27817
  for (const [key, b] of subagentBudgets) {
@@ -27818,7 +27823,13 @@ function consumeSubagentBudget(sessionKey, tokens) {
27818
27823
  }
27819
27824
  const budget = subagentBudgets.get(subagentKey(sessionKey));
27820
27825
  if (!budget) return -1;
27821
- const granted = Math.min(tokens, budget.remaining);
27826
+ const requested = Math.floor(tokens);
27827
+ if (!Number.isFinite(requested) || requested <= 0) return 0;
27828
+ if (!Number.isFinite(budget.remaining) || budget.remaining <= 0) {
27829
+ budget.remaining = 0;
27830
+ return 0;
27831
+ }
27832
+ const granted = Math.min(requested, budget.remaining);
27822
27833
  budget.remaining = Math.max(0, budget.remaining - granted);
27823
27834
  return granted;
27824
27835
  }
@@ -28148,14 +28159,16 @@ function buildContextEngineFactory(runtime, cfg, logger = console) {
28148
28159
  try {
28149
28160
  const continuityHits = await params.client.searchTextCollections({
28150
28161
  collections: [resolveUserCollection(params.userId)],
28151
- text: "__session_continuity__",
28152
- k: 1,
28162
+ text: "previous session context continuity",
28163
+ k: 8,
28153
28164
  excludeByCollection: {}
28154
28165
  });
28155
28166
  const continuityHit = continuityHits.results?.find(
28156
28167
  (r) => r.id === "__session_continuity__"
28157
28168
  );
28158
- if (!continuityHit) return null;
28169
+ if (!continuityHit) {
28170
+ return "<continuity_context>\nNo prior session context available. Use memory_search to recall previous conversations.\n</continuity_context>";
28171
+ }
28159
28172
  let meta = {};
28160
28173
  if (continuityHit.metadataJson && continuityHit.metadataJson.length > 0) {
28161
28174
  try {
@@ -28164,13 +28177,16 @@ function buildContextEngineFactory(runtime, cfg, logger = console) {
28164
28177
  }
28165
28178
  }
28166
28179
  const summaryId = meta.summary_id;
28167
- if (!summaryId) return null;
28180
+ if (!summaryId) {
28181
+ const sid = meta.session_id ?? params.sessionId;
28182
+ return "<continuity_context>\nThe previous session (" + sid + ") was not compacted. Use memory_search with queries about what was discussed to recall context.\n</continuity_context>";
28183
+ }
28168
28184
  const expanded = await params.client.expandSummary({
28169
28185
  sessionId: meta.session_id ?? params.sessionId,
28170
28186
  summaryId,
28171
28187
  maxDepth: 2
28172
28188
  });
28173
- if (!expanded.text) return null;
28189
+ if (!expanded.text) return "<continuity_context>\nFailed to expand prior session summary. Use memory_search to recall previous conversations.\n</continuity_context>";
28174
28190
  return "<continuity_context>\nThe following is a summary of the previous session. Use it for context about what was discussed before the reset.\n" + expanded.text + "\n</continuity_context>";
28175
28191
  } catch {
28176
28192
  return null;
@@ -28621,7 +28637,7 @@ function buildContextEngineFactory(runtime, cfg, logger = console) {
28621
28637
  }
28622
28638
  },
28623
28639
  async prepareSubagentSpawn(params) {
28624
- const budget = typeof cfg.subagentTokenBudget === "number" ? cfg.subagentTokenBudget : 8e3;
28640
+ const budget = normalizeSubagentTokenBudget(cfg.subagentTokenBudget);
28625
28641
  const seconds = typeof params.ttlMs === "number" && params.ttlMs > 0 ? Math.ceil(params.ttlMs / 1e3) : 120;
28626
28642
  const key = subagentKey(params.childSessionKey);
28627
28643
  subagentBudgets.set(key, {
@@ -36120,7 +36136,7 @@ function createMemoryDescribeTool(getClient, getSessionId = () => void 0, logger
36120
36136
  }
36121
36137
  };
36122
36138
  }
36123
- function createMemoryExpandTool(getClient, getSessionKey, logger = console) {
36139
+ function createMemoryExpandTool(getClient, getSessionKey, logger = console, getSessionId = () => void 0) {
36124
36140
  return {
36125
36141
  name: "memory_expand",
36126
36142
  label: "Memory Expand",
@@ -36133,7 +36149,7 @@ function createMemoryExpandTool(getClient, getSessionKey, logger = console) {
36133
36149
  if (summaryIds.length === 0) throw new Error("memory_expand requires at least one summaryId");
36134
36150
  const maxDepth = readNum(params, "maxDepth", { integer: true, min: 0 }) ?? 1;
36135
36151
  let maxTokens = readNum(params, "maxTokens", { integer: true }) ?? MAX_EXPAND_TOKENS;
36136
- const sessionId = readStr(params, "sessionId") ?? "";
36152
+ const sessionId = readStr(params, "sessionId") ?? getSessionId() ?? "";
36137
36153
  const sessionKey = getSessionKey();
36138
36154
  if (sessionKey) {
36139
36155
  const grantedTokens = consumeSubagentBudget(sessionKey, maxTokens);
@@ -40017,7 +40033,8 @@ function register(api) {
40017
40033
  api.registerTool?.((ctx) => {
40018
40034
  const getClient = runtimeOrNull.getClient;
40019
40035
  const getSessionKey = () => ctx.sessionKey;
40020
- return createMemoryExpandTool(getClient, getSessionKey, logger);
40036
+ const getSessionId = () => ctx.sessionId;
40037
+ return createMemoryExpandTool(getClient, getSessionKey, logger, getSessionId);
40021
40038
  }, { names: ["memory_expand"] });
40022
40039
  api.registerTool?.((ctx) => {
40023
40040
  const getClient = runtimeOrNull.getClient;
@@ -67,7 +67,7 @@ export declare function createMemoryDescribeTool(getClient: ClientGetter, getSes
67
67
  };
68
68
  execute: (_toolCallId: string, rawParams: unknown) => Promise<ToolResult<MemoryDescribeDetails>>;
69
69
  };
70
- export declare function createMemoryExpandTool(getClient: ClientGetter, getSessionKey: () => string | undefined, logger?: LoggerLike): {
70
+ export declare function createMemoryExpandTool(getClient: ClientGetter, getSessionKey: () => string | undefined, logger?: LoggerLike, getSessionId?: () => string | undefined): {
71
71
  name: string;
72
72
  label: string;
73
73
  description: string;
@@ -187,7 +187,7 @@ export function createMemoryDescribeTool(getClient, getSessionId = () => undefin
187
187
  },
188
188
  };
189
189
  }
190
- export function createMemoryExpandTool(getClient, getSessionKey, logger = console) {
190
+ export function createMemoryExpandTool(getClient, getSessionKey, logger = console, getSessionId = () => undefined) {
191
191
  return {
192
192
  name: "memory_expand",
193
193
  label: "Memory Expand",
@@ -204,7 +204,7 @@ export function createMemoryExpandTool(getClient, getSessionKey, logger = consol
204
204
  throw new Error("memory_expand requires at least one summaryId");
205
205
  const maxDepth = readNum(params, "maxDepth", { integer: true, min: 0 }) ?? 1;
206
206
  let maxTokens = readNum(params, "maxTokens", { integer: true }) ?? MAX_EXPAND_TOKENS;
207
- const sessionId = readStr(params, "sessionId") ?? "";
207
+ const sessionId = readStr(params, "sessionId") ?? getSessionId() ?? "";
208
208
  // Subagent budget gate: if this is a subagent, check remaining expansion budget.
209
209
  const sessionKey = getSessionKey();
210
210
  if (sessionKey) {
@@ -2,7 +2,7 @@
2
2
  "id": "libravdb-memory",
3
3
  "name": "LibraVDB Memory",
4
4
  "description": "Persistent vector memory with three-tier hybrid scoring",
5
- "version": "1.8.7",
5
+ "version": "1.8.9",
6
6
  "kind": [
7
7
  "memory",
8
8
  "context-engine"
@@ -12,7 +12,10 @@
12
12
  "contextEngine": true,
13
13
  "tools": [
14
14
  "memory_search",
15
- "memory_get"
15
+ "memory_get",
16
+ "memory_describe",
17
+ "memory_expand",
18
+ "memory_grep"
16
19
  ]
17
20
  },
18
21
  "activation": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xdarkicex/openclaw-memory-libravdb",
3
- "version": "1.8.7",
3
+ "version": "1.8.9",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",