@joshuaswarren/openclaw-engram 8.3.11 → 8.3.12
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 +65 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10157,6 +10157,59 @@ function deriveTopicsFromExtraction(result) {
|
|
|
10157
10157
|
}
|
|
10158
10158
|
return [...topics].slice(0, 16);
|
|
10159
10159
|
}
|
|
10160
|
+
function buildCompressionGuidelinesMarkdown(events, generatedAtIso = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
10161
|
+
const byAction = /* @__PURE__ */ new Map();
|
|
10162
|
+
const byOutcome = /* @__PURE__ */ new Map();
|
|
10163
|
+
for (const event of events) {
|
|
10164
|
+
byAction.set(event.action, (byAction.get(event.action) ?? 0) + 1);
|
|
10165
|
+
byOutcome.set(event.outcome, (byOutcome.get(event.outcome) ?? 0) + 1);
|
|
10166
|
+
}
|
|
10167
|
+
const actionLines = byAction.size === 0 ? ["- (none)"] : [...byAction.entries()].sort((a, b) => b[1] - a[1]).map(([action, count]) => `- ${action}: ${count}`);
|
|
10168
|
+
const outcomeLines = byOutcome.size === 0 ? ["- (none)"] : [...byOutcome.entries()].sort((a, b) => b[1] - a[1]).map(([outcome, count]) => `- ${outcome}: ${count}`);
|
|
10169
|
+
const failed = byOutcome.get("failed") ?? 0;
|
|
10170
|
+
const skipped = byOutcome.get("skipped") ?? 0;
|
|
10171
|
+
const applied = byOutcome.get("applied") ?? 0;
|
|
10172
|
+
const topAction = [...byAction.entries()].sort((a, b) => b[1] - a[1])[0]?.[0];
|
|
10173
|
+
const suggested = [];
|
|
10174
|
+
if (events.length === 0) {
|
|
10175
|
+
suggested.push(
|
|
10176
|
+
"- No telemetry events available yet. Keep defaults conservative and gather action data first."
|
|
10177
|
+
);
|
|
10178
|
+
} else {
|
|
10179
|
+
if (typeof topAction === "string") {
|
|
10180
|
+
suggested.push(`- Prefer \`${topAction}\` when handling similar future compression decisions.`);
|
|
10181
|
+
}
|
|
10182
|
+
if (failed > 0) {
|
|
10183
|
+
suggested.push(
|
|
10184
|
+
"- Failure events detected. Favor smaller, reversible compression steps and keep fail-open behavior."
|
|
10185
|
+
);
|
|
10186
|
+
}
|
|
10187
|
+
if (skipped > applied) {
|
|
10188
|
+
suggested.push(
|
|
10189
|
+
"- Skipped actions outnumber applied actions. Revisit gating/thresholds before tightening policies."
|
|
10190
|
+
);
|
|
10191
|
+
}
|
|
10192
|
+
if (failed === 0 && skipped <= applied) {
|
|
10193
|
+
suggested.push("- Current action outcomes are stable. Keep policy conservative and continue monitoring.");
|
|
10194
|
+
}
|
|
10195
|
+
}
|
|
10196
|
+
return [
|
|
10197
|
+
"# Compression Guidelines",
|
|
10198
|
+
"",
|
|
10199
|
+
`Generated: ${generatedAtIso}`,
|
|
10200
|
+
`Source events analyzed: ${events.length}`,
|
|
10201
|
+
"",
|
|
10202
|
+
"## Action Distribution",
|
|
10203
|
+
...actionLines,
|
|
10204
|
+
"",
|
|
10205
|
+
"## Outcome Distribution",
|
|
10206
|
+
...outcomeLines,
|
|
10207
|
+
"",
|
|
10208
|
+
"## Suggested Guidelines",
|
|
10209
|
+
...suggested,
|
|
10210
|
+
""
|
|
10211
|
+
].join("\n");
|
|
10212
|
+
}
|
|
10160
10213
|
function filterRecallCandidates(candidates, options) {
|
|
10161
10214
|
const scopedByNamespace = options.namespacesEnabled ? candidates.filter((r) => options.recallNamespaces.includes(options.resolveNamespace(r.path))) : candidates;
|
|
10162
10215
|
return scopedByNamespace.filter((r) => !isArtifactMemoryPath(r.path)).slice(0, Math.max(0, options.limit));
|
|
@@ -12263,6 +12316,7 @@ _Context: ${topQuestion.context}_`);
|
|
|
12263
12316
|
log.warn(`lifecycle policy pass failed (ignored): ${err}`);
|
|
12264
12317
|
}
|
|
12265
12318
|
}
|
|
12319
|
+
await this.runCompressionGuidelineLearningPass();
|
|
12266
12320
|
if (this.config.factArchivalEnabled) {
|
|
12267
12321
|
const archived = await this.runFactArchival(allMemories);
|
|
12268
12322
|
if (archived > 0) {
|
|
@@ -12324,6 +12378,17 @@ ${texts.map((t, i) => `[${i + 1}] ${t}`).join("\n\n")}`;
|
|
|
12324
12378
|
log.info("consolidation complete");
|
|
12325
12379
|
return { memoriesProcessed: allMemories.length, merged, invalidated };
|
|
12326
12380
|
}
|
|
12381
|
+
async runCompressionGuidelineLearningPass() {
|
|
12382
|
+
if (!this.config.compressionGuidelineLearningEnabled) return;
|
|
12383
|
+
try {
|
|
12384
|
+
const events = await this.storage.readMemoryActionEvents(500);
|
|
12385
|
+
const content = buildCompressionGuidelinesMarkdown(events);
|
|
12386
|
+
await this.storage.writeCompressionGuidelines(content);
|
|
12387
|
+
log.info(`compression guideline learning updated (${events.length} events)`);
|
|
12388
|
+
} catch (err) {
|
|
12389
|
+
log.warn(`compression guideline learning failed (ignored): ${err}`);
|
|
12390
|
+
}
|
|
12391
|
+
}
|
|
12327
12392
|
async runLifecyclePolicyPass(allMemories) {
|
|
12328
12393
|
const now = /* @__PURE__ */ new Date();
|
|
12329
12394
|
const nowIso = now.toISOString();
|