@joshuaswarren/openclaw-engram 8.3.10 → 8.3.11
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 +139 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10670,6 +10670,22 @@ var Orchestrator = class _Orchestrator {
|
|
|
10670
10670
|
const ns = namespace && namespace.length > 0 ? namespace : this.config.defaultNamespace;
|
|
10671
10671
|
return this.storageRouter.storageFor(ns);
|
|
10672
10672
|
}
|
|
10673
|
+
async appendMemoryActionEvent(event) {
|
|
10674
|
+
const namespace = typeof event.namespace === "string" && event.namespace.length > 0 ? event.namespace : this.config.defaultNamespace;
|
|
10675
|
+
try {
|
|
10676
|
+
const storage = await this.getStorage(namespace);
|
|
10677
|
+
const toWrite = {
|
|
10678
|
+
...event,
|
|
10679
|
+
namespace,
|
|
10680
|
+
timestamp: typeof event.timestamp === "string" && event.timestamp.length > 0 ? event.timestamp : (/* @__PURE__ */ new Date()).toISOString()
|
|
10681
|
+
};
|
|
10682
|
+
await storage.appendMemoryActionEvents([toWrite]);
|
|
10683
|
+
return true;
|
|
10684
|
+
} catch (err) {
|
|
10685
|
+
log.warn(`appendMemoryActionEvent failed (non-fatal): ${err}`);
|
|
10686
|
+
return false;
|
|
10687
|
+
}
|
|
10688
|
+
}
|
|
10673
10689
|
async getLastGraphRecallSnapshot(namespace) {
|
|
10674
10690
|
const storage = await this.getStorage(namespace);
|
|
10675
10691
|
const snapshotPath = path22.join(storage.dir, "state", "last_graph_recall.json");
|
|
@@ -12868,11 +12884,25 @@ ${lines.join("\n\n")}`;
|
|
|
12868
12884
|
|
|
12869
12885
|
// src/tools.ts
|
|
12870
12886
|
import path23 from "path";
|
|
12887
|
+
import { createHash as createHash5 } from "crypto";
|
|
12871
12888
|
import { Type } from "@sinclair/typebox";
|
|
12872
12889
|
function toolResult(text) {
|
|
12873
12890
|
return { content: [{ type: "text", text }], details: void 0 };
|
|
12874
12891
|
}
|
|
12875
12892
|
function registerTools(api, orchestrator) {
|
|
12893
|
+
const actionTypes = [
|
|
12894
|
+
"store_episode",
|
|
12895
|
+
"store_note",
|
|
12896
|
+
"update_note",
|
|
12897
|
+
"create_artifact",
|
|
12898
|
+
"summarize_node",
|
|
12899
|
+
"discard",
|
|
12900
|
+
"link_graph"
|
|
12901
|
+
];
|
|
12902
|
+
function promptHashForTelemetry(input) {
|
|
12903
|
+
if (typeof input !== "string" || input.trim().length === 0) return void 0;
|
|
12904
|
+
return createHash5("sha256").update(input).digest("hex").slice(0, 16);
|
|
12905
|
+
}
|
|
12876
12906
|
function namespaceFromPath(p) {
|
|
12877
12907
|
const m = p.match(/[\\/]+namespaces[\\/]+([^\\/]+)[\\/]+/);
|
|
12878
12908
|
return m && m[1] ? m[1] : orchestrator.config.defaultNamespace;
|
|
@@ -13114,6 +13144,112 @@ NOTE: You did not provide sessionKey; under concurrency this may not match your
|
|
|
13114
13144
|
},
|
|
13115
13145
|
{ name: "memory_feedback_last_recall" }
|
|
13116
13146
|
);
|
|
13147
|
+
api.registerTool(
|
|
13148
|
+
{
|
|
13149
|
+
name: "context_checkpoint",
|
|
13150
|
+
label: "Context Checkpoint",
|
|
13151
|
+
description: "Record a context-compression checkpoint event for policy-learning telemetry (v8.3).",
|
|
13152
|
+
parameters: Type.Object({
|
|
13153
|
+
summary: Type.String({
|
|
13154
|
+
description: "Short summary of what was checkpointed."
|
|
13155
|
+
}),
|
|
13156
|
+
sourcePrompt: Type.Optional(
|
|
13157
|
+
Type.String({
|
|
13158
|
+
description: "Optional source prompt text used for hashing in telemetry."
|
|
13159
|
+
})
|
|
13160
|
+
),
|
|
13161
|
+
namespace: Type.Optional(
|
|
13162
|
+
Type.String({
|
|
13163
|
+
description: "Optional namespace. Defaults to defaultNamespace."
|
|
13164
|
+
})
|
|
13165
|
+
)
|
|
13166
|
+
}),
|
|
13167
|
+
async execute(_toolCallId, params) {
|
|
13168
|
+
if (!orchestrator.config.contextCompressionActionsEnabled) {
|
|
13169
|
+
return toolResult(
|
|
13170
|
+
"Context compression actions are disabled. Enable `contextCompressionActionsEnabled: true` to use this tool."
|
|
13171
|
+
);
|
|
13172
|
+
}
|
|
13173
|
+
const { summary, sourcePrompt, namespace } = params;
|
|
13174
|
+
const ns = typeof namespace === "string" && namespace.length > 0 ? namespace : orchestrator.config.defaultNamespace;
|
|
13175
|
+
const wrote = await orchestrator.appendMemoryActionEvent({
|
|
13176
|
+
action: "summarize_node",
|
|
13177
|
+
outcome: "applied",
|
|
13178
|
+
namespace: ns,
|
|
13179
|
+
reason: `context_checkpoint:${summary.slice(0, 200)}`,
|
|
13180
|
+
promptHash: promptHashForTelemetry(sourcePrompt)
|
|
13181
|
+
});
|
|
13182
|
+
if (!wrote) {
|
|
13183
|
+
return toolResult("Checkpoint recorded best-effort failed (fail-open).");
|
|
13184
|
+
}
|
|
13185
|
+
return toolResult(`Recorded context checkpoint telemetry in namespace=${ns}.`);
|
|
13186
|
+
}
|
|
13187
|
+
},
|
|
13188
|
+
{ name: "context_checkpoint" }
|
|
13189
|
+
);
|
|
13190
|
+
api.registerTool(
|
|
13191
|
+
{
|
|
13192
|
+
name: "memory_action_apply",
|
|
13193
|
+
label: "Apply Memory Action",
|
|
13194
|
+
description: "Record a memory-action application event for policy-learning telemetry (v8.3).",
|
|
13195
|
+
parameters: Type.Object({
|
|
13196
|
+
action: Type.String({
|
|
13197
|
+
enum: actionTypes,
|
|
13198
|
+
description: "Memory action type."
|
|
13199
|
+
}),
|
|
13200
|
+
outcome: Type.Optional(
|
|
13201
|
+
Type.String({
|
|
13202
|
+
enum: ["applied", "skipped", "failed"],
|
|
13203
|
+
description: "Outcome status (default: applied)."
|
|
13204
|
+
})
|
|
13205
|
+
),
|
|
13206
|
+
reason: Type.Optional(
|
|
13207
|
+
Type.String({
|
|
13208
|
+
description: "Optional reason/notes for this action outcome."
|
|
13209
|
+
})
|
|
13210
|
+
),
|
|
13211
|
+
memoryId: Type.Optional(
|
|
13212
|
+
Type.String({
|
|
13213
|
+
description: "Optional memory ID targeted by this action."
|
|
13214
|
+
})
|
|
13215
|
+
),
|
|
13216
|
+
sourcePrompt: Type.Optional(
|
|
13217
|
+
Type.String({
|
|
13218
|
+
description: "Optional source prompt text used for hashing in telemetry."
|
|
13219
|
+
})
|
|
13220
|
+
),
|
|
13221
|
+
namespace: Type.Optional(
|
|
13222
|
+
Type.String({
|
|
13223
|
+
description: "Optional namespace. Defaults to defaultNamespace."
|
|
13224
|
+
})
|
|
13225
|
+
)
|
|
13226
|
+
}),
|
|
13227
|
+
async execute(_toolCallId, params) {
|
|
13228
|
+
if (!orchestrator.config.contextCompressionActionsEnabled) {
|
|
13229
|
+
return toolResult(
|
|
13230
|
+
"Context compression actions are disabled. Enable `contextCompressionActionsEnabled: true` to use this tool."
|
|
13231
|
+
);
|
|
13232
|
+
}
|
|
13233
|
+
const { action, outcome, reason, memoryId, sourcePrompt, namespace } = params;
|
|
13234
|
+
const ns = typeof namespace === "string" && namespace.length > 0 ? namespace : orchestrator.config.defaultNamespace;
|
|
13235
|
+
const wrote = await orchestrator.appendMemoryActionEvent({
|
|
13236
|
+
action,
|
|
13237
|
+
outcome: outcome ?? "applied",
|
|
13238
|
+
namespace: ns,
|
|
13239
|
+
reason,
|
|
13240
|
+
memoryId,
|
|
13241
|
+
promptHash: promptHashForTelemetry(sourcePrompt)
|
|
13242
|
+
});
|
|
13243
|
+
if (!wrote) {
|
|
13244
|
+
return toolResult("Memory action telemetry write failed (fail-open).");
|
|
13245
|
+
}
|
|
13246
|
+
return toolResult(
|
|
13247
|
+
`Recorded memory action telemetry: action=${action}, outcome=${outcome ?? "applied"}, namespace=${ns}.`
|
|
13248
|
+
);
|
|
13249
|
+
}
|
|
13250
|
+
},
|
|
13251
|
+
{ name: "memory_action_apply" }
|
|
13252
|
+
);
|
|
13117
13253
|
api.registerTool(
|
|
13118
13254
|
{
|
|
13119
13255
|
name: "memory_store",
|
|
@@ -13648,17 +13784,17 @@ var EXPORT_FORMAT = "openclaw-engram-export";
|
|
|
13648
13784
|
var EXPORT_SCHEMA_VERSION = 1;
|
|
13649
13785
|
|
|
13650
13786
|
// src/transfer/fs-utils.ts
|
|
13651
|
-
import { createHash as
|
|
13787
|
+
import { createHash as createHash6 } from "crypto";
|
|
13652
13788
|
import { mkdir as mkdir17, readdir as readdir10, readFile as readFile17, stat as stat3, writeFile as writeFile16 } from "fs/promises";
|
|
13653
13789
|
import path24 from "path";
|
|
13654
13790
|
async function sha256File(filePath) {
|
|
13655
13791
|
const buf = await readFile17(filePath);
|
|
13656
|
-
const sha256 =
|
|
13792
|
+
const sha256 = createHash6("sha256").update(buf).digest("hex");
|
|
13657
13793
|
return { sha256, bytes: buf.byteLength };
|
|
13658
13794
|
}
|
|
13659
13795
|
function sha256String(content) {
|
|
13660
13796
|
const buf = Buffer.from(content, "utf-8");
|
|
13661
|
-
const sha256 =
|
|
13797
|
+
const sha256 = createHash6("sha256").update(buf).digest("hex");
|
|
13662
13798
|
return { sha256, bytes: buf.byteLength };
|
|
13663
13799
|
}
|
|
13664
13800
|
async function writeJsonFile(filePath, value) {
|