@xdarkicex/openclaw-memory-libravdb 1.9.1 → 1.9.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.
- package/dist/context-engine.js +30 -34
- package/dist/index.js +28 -32
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
package/dist/context-engine.js
CHANGED
|
@@ -748,10 +748,6 @@ function resolveDynamicCompactThreshold(tokenBudget, compactThreshold, compactio
|
|
|
748
748
|
logger?.info?.(`[compact:trace] resolveDynamicCompactThreshold branch=explicit tokenBudget=${tokenBudget} compactThreshold=${compactThreshold} → ${val}`);
|
|
749
749
|
return val;
|
|
750
750
|
}
|
|
751
|
-
if (compactSessionTokenBudget === 0) {
|
|
752
|
-
logger?.info?.(`[compact:trace] resolveDynamicCompactThreshold branch=disabled tokenBudget=${tokenBudget}`);
|
|
753
|
-
return undefined;
|
|
754
|
-
}
|
|
755
751
|
const normalizedBudget = normalizeTokenBudget(tokenBudget);
|
|
756
752
|
if (normalizedBudget == null) {
|
|
757
753
|
logger?.info?.(`[compact:trace] resolveDynamicCompactThreshold branch=null_budget tokenBudget=${tokenBudget} → undefined`);
|
|
@@ -763,6 +759,12 @@ function resolveDynamicCompactThreshold(tokenBudget, compactThreshold, compactio
|
|
|
763
759
|
// enough turns to compact) or absurdly high (Codex Runtime 1M tokens
|
|
764
760
|
// would produce an unreachable 800k threshold).
|
|
765
761
|
const withBounds = Math.max(2000, Math.min(16000, derived));
|
|
762
|
+
// User-configured compactSessionTokenBudget overrides the ceiling.
|
|
763
|
+
if (typeof compactSessionTokenBudget === "number" && compactSessionTokenBudget > 0) {
|
|
764
|
+
const capped = Math.min(withBounds, compactSessionTokenBudget);
|
|
765
|
+
logger?.info?.(`[compact:trace] resolveDynamicCompactThreshold branch=user_cap tokenBudget=${tokenBudget} normalizedBudget=${normalizedBudget} fraction=${fraction} derived=${derived} withBounds=${withBounds} cap=${compactSessionTokenBudget} → ${capped}`);
|
|
766
|
+
return capped;
|
|
767
|
+
}
|
|
766
768
|
logger?.info?.(`[compact:trace] resolveDynamicCompactThreshold branch=clamped tokenBudget=${tokenBudget} normalizedBudget=${normalizedBudget} fraction=${fraction} derived=${derived} withBounds=${withBounds} → ${withBounds}`);
|
|
767
769
|
return withBounds;
|
|
768
770
|
}
|
|
@@ -772,13 +774,6 @@ function resolvePredictiveCompactionTarget(params) {
|
|
|
772
774
|
if (currentTokenCount == null || threshold == null || currentTokenCount < threshold) {
|
|
773
775
|
return undefined;
|
|
774
776
|
}
|
|
775
|
-
const sinceLastBudget = normalizeTokenBudget(params.compactSessionTokenBudget);
|
|
776
|
-
const lastCompactedTokenCount = normalizeCurrentTokenCount(params.lastCompactedTokenCount);
|
|
777
|
-
if (sinceLastBudget != null &&
|
|
778
|
-
lastCompactedTokenCount != null &&
|
|
779
|
-
currentTokenCount - lastCompactedTokenCount < sinceLastBudget) {
|
|
780
|
-
return undefined;
|
|
781
|
-
}
|
|
782
777
|
const belowThresholdTarget = Math.max(1, threshold - 1);
|
|
783
778
|
return belowThresholdTarget < currentTokenCount
|
|
784
779
|
? belowThresholdTarget
|
|
@@ -945,7 +940,30 @@ function canonicalizeCompactedSessionContextBlocks(text) {
|
|
|
945
940
|
catch {
|
|
946
941
|
return match;
|
|
947
942
|
}
|
|
948
|
-
|
|
943
|
+
// Keep JSON state line + first (latest, most complete) render ledger.
|
|
944
|
+
// Strip subsequent repeated render ledgers from older compaction cycles.
|
|
945
|
+
// Record boundary: second occurrence of any render-ledger heading.
|
|
946
|
+
// Use the same heading set as COMPACTED_SESSION_RENDER_LEDGER_RE.
|
|
947
|
+
const HEADING_RE = /(?:^|\n)(?:Artifacts:|Constraints:|Open Next Steps:|Extracted context anchors:)/g;
|
|
948
|
+
let headingMatch;
|
|
949
|
+
let headingCount = 0;
|
|
950
|
+
const seen = new Set();
|
|
951
|
+
let cutIdx = rest.length;
|
|
952
|
+
while ((headingMatch = HEADING_RE.exec(rest)) !== null) {
|
|
953
|
+
const heading = headingMatch[0].replace(/^\n/, "");
|
|
954
|
+
if (seen.has(heading)) {
|
|
955
|
+
// Repeat heading — second ledger starts here.
|
|
956
|
+
cutIdx = headingMatch.index;
|
|
957
|
+
break;
|
|
958
|
+
}
|
|
959
|
+
seen.add(heading);
|
|
960
|
+
headingCount++;
|
|
961
|
+
}
|
|
962
|
+
const keptRest = rest.slice(0, cutIdx).trim();
|
|
963
|
+
if (!keptRest) {
|
|
964
|
+
return `<compacted_session_context${attrs}>\n${firstLine}\n</compacted_session_context>`;
|
|
965
|
+
}
|
|
966
|
+
return `<compacted_session_context${attrs}>\n${firstLine}\n${keptRest}\n</compacted_session_context>`;
|
|
949
967
|
});
|
|
950
968
|
}
|
|
951
969
|
function demoteDaemonAuthoredContextBlocks(text) {
|
|
@@ -1596,8 +1614,6 @@ export function buildContextEngineFactory(runtime, cfg, logger = console) {
|
|
|
1596
1614
|
}
|
|
1597
1615
|
const predictiveContextCache = new Map();
|
|
1598
1616
|
const PREDICTIVE_CACHE_MAX_SIZE = 100;
|
|
1599
|
-
const predictiveCompactionCursors = new Map();
|
|
1600
|
-
const PREDICTIVE_COMPACTION_CURSOR_MAX_SIZE = 100;
|
|
1601
1617
|
// BeforeTurnKernel state
|
|
1602
1618
|
const turnCache = new TurnMemoryCache(100);
|
|
1603
1619
|
const circuitBreakers = new Map();
|
|
@@ -1795,14 +1811,6 @@ export function buildContextEngineFactory(runtime, cfg, logger = console) {
|
|
|
1795
1811
|
return scored.slice(0, maxItems).map((s) => s.prediction);
|
|
1796
1812
|
}
|
|
1797
1813
|
const getDynamicCompactThreshold = (tokenBudget) => resolveDynamicCompactThreshold(tokenBudget, cfg.compactThreshold, cfg.compactionThresholdFraction, cfg.compactSessionTokenBudget);
|
|
1798
|
-
const markPredictiveCompactionCursor = (sessionId, currentTokenCount) => {
|
|
1799
|
-
if (predictiveCompactionCursors.size >= PREDICTIVE_COMPACTION_CURSOR_MAX_SIZE) {
|
|
1800
|
-
const oldest = predictiveCompactionCursors.keys().next().value;
|
|
1801
|
-
if (oldest !== undefined)
|
|
1802
|
-
predictiveCompactionCursors.delete(oldest);
|
|
1803
|
-
}
|
|
1804
|
-
predictiveCompactionCursors.set(sessionId, currentTokenCount);
|
|
1805
|
-
};
|
|
1806
1814
|
const buildAssemblyConfig = (tokenBudget) => ({
|
|
1807
1815
|
useSessionRecallProjection: cfg.useSessionRecallProjection,
|
|
1808
1816
|
useSessionSummarySearchExperiment: cfg.useSessionSummarySearchExperiment,
|
|
@@ -2014,8 +2022,6 @@ export function buildContextEngineFactory(runtime, cfg, logger = console) {
|
|
|
2014
2022
|
const predictiveTargetSize = resolvePredictiveCompactionTarget({
|
|
2015
2023
|
currentTokenCount: currentContextTokens,
|
|
2016
2024
|
threshold: dynamicCompactThreshold,
|
|
2017
|
-
compactSessionTokenBudget: cfg.compactSessionTokenBudget,
|
|
2018
|
-
lastCompactedTokenCount: predictiveCompactionCursors.get(args.sessionId),
|
|
2019
2025
|
});
|
|
2020
2026
|
if (currentContextTokens == null ||
|
|
2021
2027
|
dynamicCompactThreshold == null ||
|
|
@@ -2038,9 +2044,6 @@ export function buildContextEngineFactory(runtime, cfg, logger = console) {
|
|
|
2038
2044
|
force: true,
|
|
2039
2045
|
currentTokenCount: currentContextTokens,
|
|
2040
2046
|
});
|
|
2041
|
-
if (compactionResult.compacted) {
|
|
2042
|
-
markPredictiveCompactionCursor(args.sessionId, currentContextTokens);
|
|
2043
|
-
}
|
|
2044
2047
|
logPredictiveCompactionOutcome({
|
|
2045
2048
|
logger,
|
|
2046
2049
|
phase: "afterTurn",
|
|
@@ -2059,7 +2062,6 @@ export function buildContextEngineFactory(runtime, cfg, logger = console) {
|
|
|
2059
2062
|
async bootstrap(args) {
|
|
2060
2063
|
const sessionId = requireSessionId(args.sessionId, "bootstrap");
|
|
2061
2064
|
predictiveContextCache.delete(sessionId);
|
|
2062
|
-
predictiveCompactionCursors.delete(sessionId);
|
|
2063
2065
|
postToolRecallCache.delete(sessionId);
|
|
2064
2066
|
asyncIngestionQueues.delete(sessionId);
|
|
2065
2067
|
const userId = resolveUserId({
|
|
@@ -2127,8 +2129,6 @@ export function buildContextEngineFactory(runtime, cfg, logger = console) {
|
|
|
2127
2129
|
const predictiveTargetSize = resolvePredictiveCompactionTarget({
|
|
2128
2130
|
currentTokenCount: currentContextTokens,
|
|
2129
2131
|
threshold: dynamicCompactThreshold,
|
|
2130
|
-
compactSessionTokenBudget: cfg.compactSessionTokenBudget,
|
|
2131
|
-
lastCompactedTokenCount: predictiveCompactionCursors.get(sessionId),
|
|
2132
2132
|
});
|
|
2133
2133
|
if (dynamicCompactThreshold != null && predictiveTargetSize != null) {
|
|
2134
2134
|
logPredictiveCompactionAttempt({
|
|
@@ -2147,9 +2147,6 @@ export function buildContextEngineFactory(runtime, cfg, logger = console) {
|
|
|
2147
2147
|
force: true,
|
|
2148
2148
|
currentTokenCount: currentContextTokens,
|
|
2149
2149
|
});
|
|
2150
|
-
if (compactionResult.compacted) {
|
|
2151
|
-
markPredictiveCompactionCursor(sessionId, currentContextTokens);
|
|
2152
|
-
}
|
|
2153
2150
|
logPredictiveCompactionOutcome({
|
|
2154
2151
|
logger,
|
|
2155
2152
|
phase: "assemble",
|
|
@@ -2533,7 +2530,6 @@ export function buildContextEngineFactory(runtime, cfg, logger = console) {
|
|
|
2533
2530
|
}
|
|
2534
2531
|
}
|
|
2535
2532
|
predictiveContextCache.clear();
|
|
2536
|
-
predictiveCompactionCursors.clear();
|
|
2537
2533
|
postToolRecallCache.clear();
|
|
2538
2534
|
asyncIngestionQueues.clear();
|
|
2539
2535
|
triggerCache.clear();
|
package/dist/index.js
CHANGED
|
@@ -36117,10 +36117,6 @@ function resolveDynamicCompactThreshold(tokenBudget, compactThreshold, compactio
|
|
|
36117
36117
|
logger?.info?.(`[compact:trace] resolveDynamicCompactThreshold branch=explicit tokenBudget=${tokenBudget} compactThreshold=${compactThreshold} \u2192 ${val}`);
|
|
36118
36118
|
return val;
|
|
36119
36119
|
}
|
|
36120
|
-
if (compactSessionTokenBudget === 0) {
|
|
36121
|
-
logger?.info?.(`[compact:trace] resolveDynamicCompactThreshold branch=disabled tokenBudget=${tokenBudget}`);
|
|
36122
|
-
return void 0;
|
|
36123
|
-
}
|
|
36124
36120
|
const normalizedBudget = normalizeTokenBudget(tokenBudget);
|
|
36125
36121
|
if (normalizedBudget == null) {
|
|
36126
36122
|
logger?.info?.(`[compact:trace] resolveDynamicCompactThreshold branch=null_budget tokenBudget=${tokenBudget} \u2192 undefined`);
|
|
@@ -36129,6 +36125,11 @@ function resolveDynamicCompactThreshold(tokenBudget, compactThreshold, compactio
|
|
|
36129
36125
|
const fraction = normalizeThresholdFraction(compactionThresholdFraction);
|
|
36130
36126
|
const derived = Math.max(1, Math.floor(normalizedBudget * fraction));
|
|
36131
36127
|
const withBounds = Math.max(2e3, Math.min(16e3, derived));
|
|
36128
|
+
if (typeof compactSessionTokenBudget === "number" && compactSessionTokenBudget > 0) {
|
|
36129
|
+
const capped = Math.min(withBounds, compactSessionTokenBudget);
|
|
36130
|
+
logger?.info?.(`[compact:trace] resolveDynamicCompactThreshold branch=user_cap tokenBudget=${tokenBudget} normalizedBudget=${normalizedBudget} fraction=${fraction} derived=${derived} withBounds=${withBounds} cap=${compactSessionTokenBudget} \u2192 ${capped}`);
|
|
36131
|
+
return capped;
|
|
36132
|
+
}
|
|
36132
36133
|
logger?.info?.(`[compact:trace] resolveDynamicCompactThreshold branch=clamped tokenBudget=${tokenBudget} normalizedBudget=${normalizedBudget} fraction=${fraction} derived=${derived} withBounds=${withBounds} \u2192 ${withBounds}`);
|
|
36133
36134
|
return withBounds;
|
|
36134
36135
|
}
|
|
@@ -36138,11 +36139,6 @@ function resolvePredictiveCompactionTarget(params) {
|
|
|
36138
36139
|
if (currentTokenCount == null || threshold == null || currentTokenCount < threshold) {
|
|
36139
36140
|
return void 0;
|
|
36140
36141
|
}
|
|
36141
|
-
const sinceLastBudget = normalizeTokenBudget(params.compactSessionTokenBudget);
|
|
36142
|
-
const lastCompactedTokenCount = normalizeCurrentTokenCount(params.lastCompactedTokenCount);
|
|
36143
|
-
if (sinceLastBudget != null && lastCompactedTokenCount != null && currentTokenCount - lastCompactedTokenCount < sinceLastBudget) {
|
|
36144
|
-
return void 0;
|
|
36145
|
-
}
|
|
36146
36142
|
const belowThresholdTarget = Math.max(1, threshold - 1);
|
|
36147
36143
|
return belowThresholdTarget < currentTokenCount ? belowThresholdTarget : Math.max(1, currentTokenCount - 1);
|
|
36148
36144
|
}
|
|
@@ -36280,8 +36276,29 @@ function canonicalizeCompactedSessionContextBlocks(text) {
|
|
|
36280
36276
|
} catch {
|
|
36281
36277
|
return match;
|
|
36282
36278
|
}
|
|
36279
|
+
const HEADING_RE = /(?:^|\n)(?:Artifacts:|Constraints:|Open Next Steps:|Extracted context anchors:)/g;
|
|
36280
|
+
let headingMatch;
|
|
36281
|
+
let headingCount = 0;
|
|
36282
|
+
const seen = /* @__PURE__ */ new Set();
|
|
36283
|
+
let cutIdx = rest.length;
|
|
36284
|
+
while ((headingMatch = HEADING_RE.exec(rest)) !== null) {
|
|
36285
|
+
const heading = headingMatch[0].replace(/^\n/, "");
|
|
36286
|
+
if (seen.has(heading)) {
|
|
36287
|
+
cutIdx = headingMatch.index;
|
|
36288
|
+
break;
|
|
36289
|
+
}
|
|
36290
|
+
seen.add(heading);
|
|
36291
|
+
headingCount++;
|
|
36292
|
+
}
|
|
36293
|
+
const keptRest = rest.slice(0, cutIdx).trim();
|
|
36294
|
+
if (!keptRest) {
|
|
36295
|
+
return `<compacted_session_context${attrs}>
|
|
36296
|
+
${firstLine}
|
|
36297
|
+
</compacted_session_context>`;
|
|
36298
|
+
}
|
|
36283
36299
|
return `<compacted_session_context${attrs}>
|
|
36284
36300
|
${firstLine}
|
|
36301
|
+
${keptRest}
|
|
36285
36302
|
</compacted_session_context>`;
|
|
36286
36303
|
});
|
|
36287
36304
|
}
|
|
@@ -36817,8 +36834,6 @@ function buildContextEngineFactory(runtime, cfg, logger = console) {
|
|
|
36817
36834
|
}
|
|
36818
36835
|
const predictiveContextCache = /* @__PURE__ */ new Map();
|
|
36819
36836
|
const PREDICTIVE_CACHE_MAX_SIZE = 100;
|
|
36820
|
-
const predictiveCompactionCursors = /* @__PURE__ */ new Map();
|
|
36821
|
-
const PREDICTIVE_COMPACTION_CURSOR_MAX_SIZE = 100;
|
|
36822
36837
|
const turnCache = new TurnMemoryCache(100);
|
|
36823
36838
|
const circuitBreakers = /* @__PURE__ */ new Map();
|
|
36824
36839
|
const CIRCUIT_STATE_MAX_SIZE = 200;
|
|
@@ -37011,13 +37026,6 @@ function buildContextEngineFactory(runtime, cfg, logger = console) {
|
|
|
37011
37026
|
cfg.compactionThresholdFraction,
|
|
37012
37027
|
cfg.compactSessionTokenBudget
|
|
37013
37028
|
);
|
|
37014
|
-
const markPredictiveCompactionCursor = (sessionId, currentTokenCount) => {
|
|
37015
|
-
if (predictiveCompactionCursors.size >= PREDICTIVE_COMPACTION_CURSOR_MAX_SIZE) {
|
|
37016
|
-
const oldest = predictiveCompactionCursors.keys().next().value;
|
|
37017
|
-
if (oldest !== void 0) predictiveCompactionCursors.delete(oldest);
|
|
37018
|
-
}
|
|
37019
|
-
predictiveCompactionCursors.set(sessionId, currentTokenCount);
|
|
37020
|
-
};
|
|
37021
37029
|
const buildAssemblyConfig = (tokenBudget) => ({
|
|
37022
37030
|
useSessionRecallProjection: cfg.useSessionRecallProjection,
|
|
37023
37031
|
useSessionSummarySearchExperiment: cfg.useSessionSummarySearchExperiment,
|
|
@@ -37209,9 +37217,7 @@ function buildContextEngineFactory(runtime, cfg, logger = console) {
|
|
|
37209
37217
|
});
|
|
37210
37218
|
const predictiveTargetSize = resolvePredictiveCompactionTarget({
|
|
37211
37219
|
currentTokenCount: currentContextTokens,
|
|
37212
|
-
threshold: dynamicCompactThreshold
|
|
37213
|
-
compactSessionTokenBudget: cfg.compactSessionTokenBudget,
|
|
37214
|
-
lastCompactedTokenCount: predictiveCompactionCursors.get(args.sessionId)
|
|
37220
|
+
threshold: dynamicCompactThreshold
|
|
37215
37221
|
});
|
|
37216
37222
|
if (currentContextTokens == null || dynamicCompactThreshold == null || predictiveTargetSize == null) {
|
|
37217
37223
|
return;
|
|
@@ -37232,9 +37238,6 @@ function buildContextEngineFactory(runtime, cfg, logger = console) {
|
|
|
37232
37238
|
force: true,
|
|
37233
37239
|
currentTokenCount: currentContextTokens
|
|
37234
37240
|
});
|
|
37235
|
-
if (compactionResult.compacted) {
|
|
37236
|
-
markPredictiveCompactionCursor(args.sessionId, currentContextTokens);
|
|
37237
|
-
}
|
|
37238
37241
|
logPredictiveCompactionOutcome({
|
|
37239
37242
|
logger,
|
|
37240
37243
|
phase: "afterTurn",
|
|
@@ -37253,7 +37256,6 @@ function buildContextEngineFactory(runtime, cfg, logger = console) {
|
|
|
37253
37256
|
async bootstrap(args) {
|
|
37254
37257
|
const sessionId = requireSessionId(args.sessionId, "bootstrap");
|
|
37255
37258
|
predictiveContextCache.delete(sessionId);
|
|
37256
|
-
predictiveCompactionCursors.delete(sessionId);
|
|
37257
37259
|
postToolRecallCache.delete(sessionId);
|
|
37258
37260
|
asyncIngestionQueues.delete(sessionId);
|
|
37259
37261
|
const userId = resolveUserId({
|
|
@@ -37316,9 +37318,7 @@ function buildContextEngineFactory(runtime, cfg, logger = console) {
|
|
|
37316
37318
|
const dynamicCompactThreshold = getDynamicCompactThreshold(args.tokenBudget);
|
|
37317
37319
|
const predictiveTargetSize = resolvePredictiveCompactionTarget({
|
|
37318
37320
|
currentTokenCount: currentContextTokens,
|
|
37319
|
-
threshold: dynamicCompactThreshold
|
|
37320
|
-
compactSessionTokenBudget: cfg.compactSessionTokenBudget,
|
|
37321
|
-
lastCompactedTokenCount: predictiveCompactionCursors.get(sessionId)
|
|
37321
|
+
threshold: dynamicCompactThreshold
|
|
37322
37322
|
});
|
|
37323
37323
|
if (dynamicCompactThreshold != null && predictiveTargetSize != null) {
|
|
37324
37324
|
logPredictiveCompactionAttempt({
|
|
@@ -37337,9 +37337,6 @@ function buildContextEngineFactory(runtime, cfg, logger = console) {
|
|
|
37337
37337
|
force: true,
|
|
37338
37338
|
currentTokenCount: currentContextTokens
|
|
37339
37339
|
});
|
|
37340
|
-
if (compactionResult.compacted) {
|
|
37341
|
-
markPredictiveCompactionCursor(sessionId, currentContextTokens);
|
|
37342
|
-
}
|
|
37343
37340
|
logPredictiveCompactionOutcome({
|
|
37344
37341
|
logger,
|
|
37345
37342
|
phase: "assemble",
|
|
@@ -37720,7 +37717,6 @@ function buildContextEngineFactory(runtime, cfg, logger = console) {
|
|
|
37720
37717
|
}
|
|
37721
37718
|
}
|
|
37722
37719
|
predictiveContextCache.clear();
|
|
37723
|
-
predictiveCompactionCursors.clear();
|
|
37724
37720
|
postToolRecallCache.clear();
|
|
37725
37721
|
asyncIngestionQueues.clear();
|
|
37726
37722
|
triggerCache.clear();
|
package/openclaw.plugin.json
CHANGED