@xdarkicex/openclaw-memory-libravdb 1.8.1 → 1.8.2

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.
@@ -43,6 +43,19 @@ function requireSessionId(sessionId, operation) {
43
43
  function normalizeCompactResult(response, options = {}) {
44
44
  const didCompact = response?.didCompact === true;
45
45
  const tokensBefore = normalizeCurrentTokenCount(options.tokensBefore) ?? 0;
46
+ const lastCompactedTurn = typeof response?.lastCompactedTurn === "bigint" ? response.lastCompactedTurn : undefined;
47
+ const tokenAccumulatorAfter = typeof response?.tokenAccumulatorAfter === "number" ? response.tokenAccumulatorAfter : undefined;
48
+ const totalTurns = typeof response?.totalTurns === "bigint" ? response.totalTurns : undefined;
49
+ const skippedNoNewTurns = typeof response?.skippedNoNewTurns === "boolean" ? response.skippedNoNewTurns : undefined;
50
+ if (lastCompactedTurn != null ||
51
+ tokenAccumulatorAfter != null ||
52
+ totalTurns != null ||
53
+ skippedNoNewTurns != null) {
54
+ options.logger?.info?.(`[compact:trace] daemon state lastCompactedTurn=${lastCompactedTurn?.toString() ?? "unknown"} ` +
55
+ `tokenAccumulatorAfter=${tokenAccumulatorAfter ?? "unknown"} ` +
56
+ `totalTurns=${totalTurns?.toString() ?? "unknown"} ` +
57
+ `skippedNoNewTurns=${skippedNoNewTurns ?? "unknown"}`);
58
+ }
46
59
  const details = {
47
60
  clustersFormed: typeof response?.clustersFormed === "number" ? response.clustersFormed : undefined,
48
61
  clustersDeclined: typeof response?.clustersDeclined === "number" ? response.clustersDeclined : undefined,
@@ -54,6 +67,10 @@ function normalizeCompactResult(response, options = {}) {
54
67
  summaryText: typeof response?.summaryText === "string" && response.summaryText.length > 0
55
68
  ? response.summaryText
56
69
  : undefined,
70
+ ...(lastCompactedTurn != null ? { lastCompactedTurn: lastCompactedTurn.toString() } : {}),
71
+ ...(tokenAccumulatorAfter != null ? { tokenAccumulatorAfter } : {}),
72
+ ...(totalTurns != null ? { totalTurns: totalTurns.toString() } : {}),
73
+ ...(skippedNoNewTurns != null ? { skippedNoNewTurns } : {}),
57
74
  };
58
75
  // When the engine owns compaction but refuses to compact while the session
59
76
  // exceeds the threshold, this is not a successful skip — it's a failure.
@@ -363,16 +380,32 @@ function normalizeThresholdFraction(fraction) {
363
380
  /**
364
381
  * Resolves the dynamic compaction threshold from budget and threshold params.
365
382
  */
366
- function resolveDynamicCompactThreshold(tokenBudget, compactThreshold, compactionThresholdFraction) {
383
+ function resolveDynamicCompactThreshold(tokenBudget, compactThreshold, compactionThresholdFraction, compactSessionTokenBudget, logger) {
384
+ // Explicit compactThreshold always wins.
367
385
  if (typeof compactThreshold === "number" && Number.isFinite(compactThreshold) && compactThreshold > 0) {
368
- return Math.max(1, Math.floor(compactThreshold));
386
+ const val = Math.max(1, Math.floor(compactThreshold));
387
+ logger?.info?.(`[compact:trace] resolveDynamicCompactThreshold branch=explicit tokenBudget=${tokenBudget} compactThreshold=${compactThreshold} → ${val}`);
388
+ return val;
369
389
  }
370
390
  const normalizedBudget = normalizeTokenBudget(tokenBudget);
371
391
  if (normalizedBudget == null) {
392
+ logger?.info?.(`[compact:trace] resolveDynamicCompactThreshold branch=null_budget tokenBudget=${tokenBudget} → undefined`);
372
393
  return undefined;
373
394
  }
374
395
  const fraction = normalizeThresholdFraction(compactionThresholdFraction);
375
- return Math.max(1, Math.floor(normalizedBudget * fraction));
396
+ const derived = Math.max(1, Math.floor(normalizedBudget * fraction));
397
+ // Clamp to a safe range so the threshold is never absurdly low (not
398
+ // enough turns to compact) or absurdly high (Codex Runtime 1M tokens
399
+ // would produce an unreachable 800k threshold).
400
+ const withBounds = Math.max(2000, Math.min(16000, derived));
401
+ // User-configured compactSessionTokenBudget overrides the ceiling.
402
+ if (typeof compactSessionTokenBudget === "number" && compactSessionTokenBudget > 0) {
403
+ const capped = Math.min(withBounds, compactSessionTokenBudget);
404
+ logger?.info?.(`[compact:trace] resolveDynamicCompactThreshold branch=user_cap tokenBudget=${tokenBudget} normalizedBudget=${normalizedBudget} fraction=${fraction} derived=${derived} withBounds=${withBounds} cap=${compactSessionTokenBudget} → ${capped}`);
405
+ return capped;
406
+ }
407
+ logger?.info?.(`[compact:trace] resolveDynamicCompactThreshold branch=clamped tokenBudget=${tokenBudget} normalizedBudget=${normalizedBudget} fraction=${fraction} derived=${derived} withBounds=${withBounds} → ${withBounds}`);
408
+ return withBounds;
376
409
  }
377
410
  function resolvePredictiveCompactionTarget(params) {
378
411
  const currentTokenCount = normalizeCurrentTokenCount(params.currentTokenCount);
@@ -1184,7 +1217,7 @@ export function buildContextEngineFactory(runtime, cfg, logger = console) {
1184
1217
  scored.sort((a, b) => b.score - a.score);
1185
1218
  return scored.slice(0, maxItems).map((s) => s.prediction);
1186
1219
  }
1187
- const getDynamicCompactThreshold = (tokenBudget) => resolveDynamicCompactThreshold(tokenBudget, cfg.compactThreshold, cfg.compactionThresholdFraction);
1220
+ const getDynamicCompactThreshold = (tokenBudget) => resolveDynamicCompactThreshold(tokenBudget, cfg.compactThreshold, cfg.compactionThresholdFraction, cfg.compactSessionTokenBudget);
1188
1221
  const buildAssemblyConfig = (tokenBudget) => ({
1189
1222
  useSessionRecallProjection: cfg.useSessionRecallProjection,
1190
1223
  useSessionSummarySearchExperiment: cfg.useSessionSummarySearchExperiment,
@@ -1331,6 +1364,7 @@ export function buildContextEngineFactory(runtime, cfg, logger = console) {
1331
1364
  const threshold = getDynamicCompactThreshold(args.tokenBudget);
1332
1365
  return normalizeCompactResult(await client.compactSession(request), {
1333
1366
  tokensBefore: args.currentTokenCount,
1367
+ logger,
1334
1368
  ...(threshold != null ? { threshold } : {}),
1335
1369
  });
1336
1370
  }
package/dist/index.js CHANGED
@@ -26813,13 +26813,26 @@ function requireSessionId(sessionId, operation) {
26813
26813
  function normalizeCompactResult(response, options = {}) {
26814
26814
  const didCompact = response?.didCompact === true;
26815
26815
  const tokensBefore = normalizeCurrentTokenCount(options.tokensBefore) ?? 0;
26816
+ const lastCompactedTurn = typeof response?.lastCompactedTurn === "bigint" ? response.lastCompactedTurn : void 0;
26817
+ const tokenAccumulatorAfter = typeof response?.tokenAccumulatorAfter === "number" ? response.tokenAccumulatorAfter : void 0;
26818
+ const totalTurns = typeof response?.totalTurns === "bigint" ? response.totalTurns : void 0;
26819
+ const skippedNoNewTurns = typeof response?.skippedNoNewTurns === "boolean" ? response.skippedNoNewTurns : void 0;
26820
+ if (lastCompactedTurn != null || tokenAccumulatorAfter != null || totalTurns != null || skippedNoNewTurns != null) {
26821
+ options.logger?.info?.(
26822
+ `[compact:trace] daemon state lastCompactedTurn=${lastCompactedTurn?.toString() ?? "unknown"} tokenAccumulatorAfter=${tokenAccumulatorAfter ?? "unknown"} totalTurns=${totalTurns?.toString() ?? "unknown"} skippedNoNewTurns=${skippedNoNewTurns ?? "unknown"}`
26823
+ );
26824
+ }
26816
26825
  const details = {
26817
26826
  clustersFormed: typeof response?.clustersFormed === "number" ? response.clustersFormed : void 0,
26818
26827
  clustersDeclined: typeof response?.clustersDeclined === "number" ? response.clustersDeclined : void 0,
26819
26828
  turnsRemoved: typeof response?.turnsRemoved === "number" ? response.turnsRemoved : void 0,
26820
26829
  summaryMethod: typeof response?.summaryMethod === "string" && response.summaryMethod.length > 0 ? response.summaryMethod : void 0,
26821
26830
  meanConfidence: typeof response?.meanConfidence === "number" ? response.meanConfidence : void 0,
26822
- summaryText: typeof response?.summaryText === "string" && response.summaryText.length > 0 ? response.summaryText : void 0
26831
+ summaryText: typeof response?.summaryText === "string" && response.summaryText.length > 0 ? response.summaryText : void 0,
26832
+ ...lastCompactedTurn != null ? { lastCompactedTurn: lastCompactedTurn.toString() } : {},
26833
+ ...tokenAccumulatorAfter != null ? { tokenAccumulatorAfter } : {},
26834
+ ...totalTurns != null ? { totalTurns: totalTurns.toString() } : {},
26835
+ ...skippedNoNewTurns != null ? { skippedNoNewTurns } : {}
26823
26836
  };
26824
26837
  const threshold = options.threshold;
26825
26838
  const overBudget = threshold != null && tokensBefore >= threshold;
@@ -27082,16 +27095,27 @@ function normalizeThresholdFraction(fraction) {
27082
27095
  }
27083
27096
  return Math.min(0.99, Math.max(0.05, fraction));
27084
27097
  }
27085
- function resolveDynamicCompactThreshold(tokenBudget, compactThreshold, compactionThresholdFraction) {
27098
+ function resolveDynamicCompactThreshold(tokenBudget, compactThreshold, compactionThresholdFraction, compactSessionTokenBudget, logger) {
27086
27099
  if (typeof compactThreshold === "number" && Number.isFinite(compactThreshold) && compactThreshold > 0) {
27087
- return Math.max(1, Math.floor(compactThreshold));
27100
+ const val = Math.max(1, Math.floor(compactThreshold));
27101
+ logger?.info?.(`[compact:trace] resolveDynamicCompactThreshold branch=explicit tokenBudget=${tokenBudget} compactThreshold=${compactThreshold} \u2192 ${val}`);
27102
+ return val;
27088
27103
  }
27089
27104
  const normalizedBudget = normalizeTokenBudget(tokenBudget);
27090
27105
  if (normalizedBudget == null) {
27106
+ logger?.info?.(`[compact:trace] resolveDynamicCompactThreshold branch=null_budget tokenBudget=${tokenBudget} \u2192 undefined`);
27091
27107
  return void 0;
27092
27108
  }
27093
27109
  const fraction = normalizeThresholdFraction(compactionThresholdFraction);
27094
- return Math.max(1, Math.floor(normalizedBudget * fraction));
27110
+ const derived = Math.max(1, Math.floor(normalizedBudget * fraction));
27111
+ const withBounds = Math.max(2e3, Math.min(16e3, derived));
27112
+ if (typeof compactSessionTokenBudget === "number" && compactSessionTokenBudget > 0) {
27113
+ const capped = Math.min(withBounds, compactSessionTokenBudget);
27114
+ logger?.info?.(`[compact:trace] resolveDynamicCompactThreshold branch=user_cap tokenBudget=${tokenBudget} normalizedBudget=${normalizedBudget} fraction=${fraction} derived=${derived} withBounds=${withBounds} cap=${compactSessionTokenBudget} \u2192 ${capped}`);
27115
+ return capped;
27116
+ }
27117
+ logger?.info?.(`[compact:trace] resolveDynamicCompactThreshold branch=clamped tokenBudget=${tokenBudget} normalizedBudget=${normalizedBudget} fraction=${fraction} derived=${derived} withBounds=${withBounds} \u2192 ${withBounds}`);
27118
+ return withBounds;
27095
27119
  }
27096
27120
  function resolvePredictiveCompactionTarget(params) {
27097
27121
  const currentTokenCount = normalizeCurrentTokenCount(params.currentTokenCount);
@@ -27761,7 +27785,8 @@ function buildContextEngineFactory(runtime, cfg, logger = console) {
27761
27785
  const getDynamicCompactThreshold = (tokenBudget) => resolveDynamicCompactThreshold(
27762
27786
  tokenBudget,
27763
27787
  cfg.compactThreshold,
27764
- cfg.compactionThresholdFraction
27788
+ cfg.compactionThresholdFraction,
27789
+ cfg.compactSessionTokenBudget
27765
27790
  );
27766
27791
  const buildAssemblyConfig = (tokenBudget) => ({
27767
27792
  useSessionRecallProjection: cfg.useSessionRecallProjection,
@@ -27897,6 +27922,7 @@ function buildContextEngineFactory(runtime, cfg, logger = console) {
27897
27922
  const threshold = getDynamicCompactThreshold(args.tokenBudget);
27898
27923
  return normalizeCompactResult(await client.compactSession(request3), {
27899
27924
  tokensBefore: args.currentTokenCount,
27925
+ logger,
27900
27926
  ...threshold != null ? { threshold } : {}
27901
27927
  });
27902
27928
  } catch (error2) {
@@ -28412,7 +28438,7 @@ import path3 from "node:path";
28412
28438
  var proxy_exports = {};
28413
28439
  __reExport(proxy_exports, __toESM(require_cjs(), 1));
28414
28440
 
28415
- // node_modules/.pnpm/@xdarkicex+libravdb-contracts@2.0.19/node_modules/@xdarkicex/libravdb-contracts/gen/js/libravdb/ipc/v1/rpc_pb.js
28441
+ // node_modules/.pnpm/@xdarkicex+libravdb-contracts@2.0.20/node_modules/@xdarkicex/libravdb-contracts/gen/js/libravdb/ipc/v1/rpc_pb.js
28416
28442
  var IngestMode;
28417
28443
  (function(IngestMode2) {
28418
28444
  IngestMode2[IngestMode2["REPLACE"] = 0] = "REPLACE";
@@ -29820,11 +29846,28 @@ var CompactSessionResponse = class _CompactSessionResponse extends proxy_exports
29820
29846
  */
29821
29847
  summaryText = "";
29822
29848
  /**
29823
- * estimated token count after compaction
29824
- *
29825
29849
  * @generated from field: int32 tokens_after = 8;
29826
29850
  */
29827
29851
  tokensAfter = 0;
29852
+ /**
29853
+ * Engine-owned session state after the compaction attempt.
29854
+ * Zero / false when the daemon is older and does not populate these.
29855
+ *
29856
+ * @generated from field: int64 last_compacted_turn = 9;
29857
+ */
29858
+ lastCompactedTurn = proxy_exports.protoInt64.zero;
29859
+ /**
29860
+ * @generated from field: int32 token_accumulator_after = 10;
29861
+ */
29862
+ tokenAccumulatorAfter = 0;
29863
+ /**
29864
+ * @generated from field: int64 total_turns = 11;
29865
+ */
29866
+ totalTurns = proxy_exports.protoInt64.zero;
29867
+ /**
29868
+ * @generated from field: bool skipped_no_new_turns = 12;
29869
+ */
29870
+ skippedNoNewTurns = false;
29828
29871
  constructor(data) {
29829
29872
  super();
29830
29873
  proxy_exports.proto3.util.initPartial(data, this);
@@ -29887,6 +29930,34 @@ var CompactSessionResponse = class _CompactSessionResponse extends proxy_exports
29887
29930
  kind: "scalar",
29888
29931
  T: 5
29889
29932
  /* ScalarType.INT32 */
29933
+ },
29934
+ {
29935
+ no: 9,
29936
+ name: "last_compacted_turn",
29937
+ kind: "scalar",
29938
+ T: 3
29939
+ /* ScalarType.INT64 */
29940
+ },
29941
+ {
29942
+ no: 10,
29943
+ name: "token_accumulator_after",
29944
+ kind: "scalar",
29945
+ T: 5
29946
+ /* ScalarType.INT32 */
29947
+ },
29948
+ {
29949
+ no: 11,
29950
+ name: "total_turns",
29951
+ kind: "scalar",
29952
+ T: 3
29953
+ /* ScalarType.INT64 */
29954
+ },
29955
+ {
29956
+ no: 12,
29957
+ name: "skipped_no_new_turns",
29958
+ kind: "scalar",
29959
+ T: 8
29960
+ /* ScalarType.BOOL */
29890
29961
  }
29891
29962
  ]);
29892
29963
  static fromBinary(bytes, options) {
@@ -38667,7 +38738,7 @@ function createGrpcTransport(options) {
38667
38738
  return createTransport(validateNodeTransportOptions(options));
38668
38739
  }
38669
38740
 
38670
- // node_modules/.pnpm/@xdarkicex+libravdb-contracts@2.0.19/node_modules/@xdarkicex/libravdb-contracts/gen/js/libravdb/ipc/v1/rpc_connect.js
38741
+ // node_modules/.pnpm/@xdarkicex+libravdb-contracts@2.0.20/node_modules/@xdarkicex/libravdb-contracts/gen/js/libravdb/ipc/v1/rpc_connect.js
38671
38742
  var LibravDB = {
38672
38743
  typeName: "libravdb.ipc.v1.LibravDB",
38673
38744
  methods: {
@@ -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.1",
5
+ "version": "1.8.2",
6
6
  "kind": [
7
7
  "memory",
8
8
  "context-engine"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xdarkicex/openclaw-memory-libravdb",
3
- "version": "1.8.1",
3
+ "version": "1.8.2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -79,6 +79,6 @@
79
79
  "dependencies": {
80
80
  "@connectrpc/connect": "^1.7.0",
81
81
  "@connectrpc/connect-node": "^1.7.0",
82
- "@xdarkicex/libravdb-contracts": "^2.0.19"
82
+ "@xdarkicex/libravdb-contracts": "^2.0.20"
83
83
  }
84
84
  }