@joshuaswarren/openclaw-engram 9.0.86 → 9.0.88
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/index.js +43 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -18117,16 +18117,21 @@ var LcmEngine = class {
|
|
|
18117
18117
|
budgetChars: effectiveBudget
|
|
18118
18118
|
});
|
|
18119
18119
|
}
|
|
18120
|
-
/**
|
|
18121
|
-
async
|
|
18120
|
+
/** Flush pending summaries before compaction (called from before_compaction hook). */
|
|
18121
|
+
async preCompactionFlush(sessionId) {
|
|
18122
18122
|
if (!this.config.enabled) return;
|
|
18123
18123
|
await this.ensureInitialized();
|
|
18124
|
-
const maxTurn = this.archive.getMaxTurnIndex(sessionId);
|
|
18125
18124
|
try {
|
|
18126
18125
|
await this.summarizer.summarizeIncremental(sessionId);
|
|
18127
18126
|
} catch (err) {
|
|
18128
18127
|
log.debug(`LCM pre-compaction flush error: ${err}`);
|
|
18129
18128
|
}
|
|
18129
|
+
}
|
|
18130
|
+
/** Record a compaction event with real token counts (called from after_compaction hook). */
|
|
18131
|
+
async recordCompaction(sessionId, tokensBefore, tokensAfter) {
|
|
18132
|
+
if (!this.config.enabled) return;
|
|
18133
|
+
await this.ensureInitialized();
|
|
18134
|
+
const maxTurn = this.archive.getMaxTurnIndex(sessionId);
|
|
18130
18135
|
this.dag.recordCompaction(sessionId, maxTurn, tokensBefore, tokensAfter);
|
|
18131
18136
|
log.info(
|
|
18132
18137
|
`LCM compaction recorded: session=${sessionId}, turn=${maxTurn}, tokens ${tokensBefore}\u2192${tokensAfter}`
|
|
@@ -42033,6 +42038,7 @@ Use this context naturally when relevant. Never quote or expose this memory cont
|
|
|
42033
42038
|
`skipping legacy typed agent_heartbeat hook for OpenClaw ${runtimeVersion}; published builds from 2026.1.29 onward do not expose it`
|
|
42034
42039
|
);
|
|
42035
42040
|
}
|
|
42041
|
+
const lcmTokensBefore = /* @__PURE__ */ new Map();
|
|
42036
42042
|
api.on(
|
|
42037
42043
|
"before_compaction",
|
|
42038
42044
|
async (event, ctx) => {
|
|
@@ -42040,8 +42046,24 @@ Use this context naturally when relevant. Never quote or expose this memory cont
|
|
|
42040
42046
|
try {
|
|
42041
42047
|
if (orchestrator.lcmEngine?.enabled) {
|
|
42042
42048
|
try {
|
|
42043
|
-
|
|
42044
|
-
|
|
42049
|
+
let tokensBefore = 0;
|
|
42050
|
+
if (typeof event.tokenCount === "number") {
|
|
42051
|
+
tokensBefore = event.tokenCount;
|
|
42052
|
+
} else if (Array.isArray(event.messages)) {
|
|
42053
|
+
for (const msg of event.messages) {
|
|
42054
|
+
if (typeof msg.content === "string") {
|
|
42055
|
+
tokensBefore += estimateTokens2(msg.content);
|
|
42056
|
+
} else if (Array.isArray(msg.content)) {
|
|
42057
|
+
for (const block of msg.content) {
|
|
42058
|
+
if (typeof block === "string") tokensBefore += estimateTokens2(block);
|
|
42059
|
+
else if (block && typeof block === "object" && typeof block.text === "string")
|
|
42060
|
+
tokensBefore += estimateTokens2(block.text);
|
|
42061
|
+
}
|
|
42062
|
+
}
|
|
42063
|
+
}
|
|
42064
|
+
}
|
|
42065
|
+
lcmTokensBefore.set(sessionKey, tokensBefore);
|
|
42066
|
+
await orchestrator.lcmEngine.preCompactionFlush(sessionKey);
|
|
42045
42067
|
} catch (lcmErr) {
|
|
42046
42068
|
log.debug(`LCM before_compaction error: ${lcmErr}`);
|
|
42047
42069
|
}
|
|
@@ -42072,9 +42094,24 @@ Use this context naturally when relevant. Never quote or expose this memory cont
|
|
|
42072
42094
|
try {
|
|
42073
42095
|
if (orchestrator.lcmEngine?.enabled) {
|
|
42074
42096
|
try {
|
|
42097
|
+
let tokensAfter = 0;
|
|
42098
|
+
if (typeof event.tokenCount === "number") {
|
|
42099
|
+
tokensAfter = event.tokenCount;
|
|
42100
|
+
} else {
|
|
42101
|
+
const storedBefore = lcmTokensBefore.get(sessionKey) ?? 0;
|
|
42102
|
+
const msgCountAfter = typeof event.messageCount === "number" ? event.messageCount : 0;
|
|
42103
|
+
const compacted = typeof event.compactedCount === "number" ? event.compactedCount : 0;
|
|
42104
|
+
const msgCountBefore = msgCountAfter + compacted;
|
|
42105
|
+
if (storedBefore > 0 && msgCountBefore > 0) {
|
|
42106
|
+
tokensAfter = Math.round(storedBefore * (msgCountAfter / msgCountBefore));
|
|
42107
|
+
}
|
|
42108
|
+
}
|
|
42109
|
+
const tokensBefore = lcmTokensBefore.get(sessionKey) ?? 0;
|
|
42110
|
+
lcmTokensBefore.delete(sessionKey);
|
|
42111
|
+
await orchestrator.lcmEngine.recordCompaction(sessionKey, tokensBefore, tokensAfter);
|
|
42075
42112
|
await orchestrator.lcmEngine.verifyPostCompaction(sessionKey);
|
|
42076
42113
|
} catch (lcmErr) {
|
|
42077
|
-
log.debug(`LCM after_compaction
|
|
42114
|
+
log.debug(`LCM after_compaction error: ${lcmErr}`);
|
|
42078
42115
|
}
|
|
42079
42116
|
}
|
|
42080
42117
|
if (!orchestrator.config.compactionResetEnabled) {
|