@joshuaswarren/openclaw-engram 8.3.65 → 8.3.67
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 +97 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1604,6 +1604,31 @@ var FallbackLlmClient = class {
|
|
|
1604
1604
|
|
|
1605
1605
|
// src/schemas.ts
|
|
1606
1606
|
import { z } from "zod";
|
|
1607
|
+
var MemoryActionTypeSchema = z.enum([
|
|
1608
|
+
"store_episode",
|
|
1609
|
+
"store_note",
|
|
1610
|
+
"update_note",
|
|
1611
|
+
"create_artifact",
|
|
1612
|
+
"summarize_node",
|
|
1613
|
+
"discard",
|
|
1614
|
+
"link_graph"
|
|
1615
|
+
]);
|
|
1616
|
+
var MemoryActionEligibilityContextSchema = z.object({
|
|
1617
|
+
confidence: z.number().min(0).max(1),
|
|
1618
|
+
lifecycleState: z.enum(["active", "validated", "candidate", "stale", "archived"]),
|
|
1619
|
+
importance: z.number().min(0).max(1),
|
|
1620
|
+
source: z.enum(["extraction", "consolidation", "replay", "manual", "unknown"])
|
|
1621
|
+
}).strict();
|
|
1622
|
+
function parseMemoryActionEligibilityContext(value) {
|
|
1623
|
+
const parsed = MemoryActionEligibilityContextSchema.safeParse(value);
|
|
1624
|
+
if (parsed.success) return parsed.data;
|
|
1625
|
+
return {
|
|
1626
|
+
confidence: 0,
|
|
1627
|
+
lifecycleState: "candidate",
|
|
1628
|
+
importance: 0,
|
|
1629
|
+
source: "unknown"
|
|
1630
|
+
};
|
|
1631
|
+
}
|
|
1607
1632
|
var ExtractedFactSchema = z.object({
|
|
1608
1633
|
category: z.enum(["fact", "preference", "correction", "entity", "decision", "relationship", "principle", "commitment", "moment", "skill"]),
|
|
1609
1634
|
content: z.string().describe("The memory content \u2014 a clear, standalone statement"),
|
|
@@ -9492,6 +9517,59 @@ function buildRecallQueryPolicy(prompt, sessionKey, cfg) {
|
|
|
9492
9517
|
};
|
|
9493
9518
|
}
|
|
9494
9519
|
|
|
9520
|
+
// src/memory-action-policy.ts
|
|
9521
|
+
var HIGH_IMPORTANCE_DISCARD_THRESHOLD = 0.8;
|
|
9522
|
+
var LOW_CONFIDENCE_DEFER_THRESHOLD = 0.35;
|
|
9523
|
+
function evaluateMemoryActionPolicy(input) {
|
|
9524
|
+
const { action, eligibility, options } = input;
|
|
9525
|
+
if (!options.actionsEnabled) {
|
|
9526
|
+
return {
|
|
9527
|
+
action,
|
|
9528
|
+
decision: "deny",
|
|
9529
|
+
rationale: "contextCompressionActionsEnabled=false",
|
|
9530
|
+
eligibility
|
|
9531
|
+
};
|
|
9532
|
+
}
|
|
9533
|
+
if (options.maxCompressionTokensPerHour === 0 && action === "summarize_node") {
|
|
9534
|
+
return {
|
|
9535
|
+
action,
|
|
9536
|
+
decision: "defer",
|
|
9537
|
+
rationale: "maxCompressionTokensPerHour=0",
|
|
9538
|
+
eligibility
|
|
9539
|
+
};
|
|
9540
|
+
}
|
|
9541
|
+
if (action === "discard" && eligibility.importance >= HIGH_IMPORTANCE_DISCARD_THRESHOLD) {
|
|
9542
|
+
return {
|
|
9543
|
+
action,
|
|
9544
|
+
decision: "deny",
|
|
9545
|
+
rationale: "importance_too_high_for_discard",
|
|
9546
|
+
eligibility
|
|
9547
|
+
};
|
|
9548
|
+
}
|
|
9549
|
+
if ((eligibility.lifecycleState === "archived" || eligibility.lifecycleState === "stale") && (action === "update_note" || action === "create_artifact" || action === "link_graph")) {
|
|
9550
|
+
return {
|
|
9551
|
+
action,
|
|
9552
|
+
decision: "deny",
|
|
9553
|
+
rationale: `lifecycle_state_${eligibility.lifecycleState}_restricted`,
|
|
9554
|
+
eligibility
|
|
9555
|
+
};
|
|
9556
|
+
}
|
|
9557
|
+
if (eligibility.source !== "unknown" && eligibility.confidence < LOW_CONFIDENCE_DEFER_THRESHOLD && action !== "discard") {
|
|
9558
|
+
return {
|
|
9559
|
+
action,
|
|
9560
|
+
decision: "defer",
|
|
9561
|
+
rationale: "confidence_below_threshold",
|
|
9562
|
+
eligibility
|
|
9563
|
+
};
|
|
9564
|
+
}
|
|
9565
|
+
return {
|
|
9566
|
+
action,
|
|
9567
|
+
decision: "allow",
|
|
9568
|
+
rationale: "eligible",
|
|
9569
|
+
eligibility
|
|
9570
|
+
};
|
|
9571
|
+
}
|
|
9572
|
+
|
|
9495
9573
|
// src/compression-optimizer.ts
|
|
9496
9574
|
var MAX_DELTA = 0.15;
|
|
9497
9575
|
var SPARSE_SAMPLE = 5;
|
|
@@ -13189,10 +13267,28 @@ var Orchestrator = class _Orchestrator {
|
|
|
13189
13267
|
const namespace = typeof event.namespace === "string" && event.namespace.length > 0 ? event.namespace : this.config.defaultNamespace;
|
|
13190
13268
|
try {
|
|
13191
13269
|
const storage = await this.getStorage(namespace);
|
|
13270
|
+
const eligibility = parseMemoryActionEligibilityContext(event.policyEligibility);
|
|
13271
|
+
const policy = evaluateMemoryActionPolicy({
|
|
13272
|
+
action: event.action,
|
|
13273
|
+
eligibility,
|
|
13274
|
+
options: {
|
|
13275
|
+
actionsEnabled: this.config.contextCompressionActionsEnabled,
|
|
13276
|
+
maxCompressionTokensPerHour: this.config.maxCompressionTokensPerHour
|
|
13277
|
+
}
|
|
13278
|
+
});
|
|
13279
|
+
const normalizedOutcome = policy.decision === "allow" ? event.outcome : event.outcome === "failed" ? "failed" : "skipped";
|
|
13280
|
+
const reasonParts = [event.reason, `policy:${policy.decision}`, policy.rationale].filter(
|
|
13281
|
+
(part) => typeof part === "string" && part.length > 0
|
|
13282
|
+
);
|
|
13192
13283
|
const toWrite = {
|
|
13193
13284
|
...event,
|
|
13285
|
+
outcome: normalizedOutcome,
|
|
13286
|
+
reason: reasonParts.join(" | "),
|
|
13194
13287
|
namespace,
|
|
13195
|
-
timestamp: typeof event.timestamp === "string" && event.timestamp.length > 0 ? event.timestamp : (/* @__PURE__ */ new Date()).toISOString()
|
|
13288
|
+
timestamp: typeof event.timestamp === "string" && event.timestamp.length > 0 ? event.timestamp : (/* @__PURE__ */ new Date()).toISOString(),
|
|
13289
|
+
policyDecision: policy.decision,
|
|
13290
|
+
policyRationale: policy.rationale,
|
|
13291
|
+
policyEligibility: eligibility
|
|
13196
13292
|
};
|
|
13197
13293
|
await storage.appendMemoryActionEvents([toWrite]);
|
|
13198
13294
|
return true;
|