@joshuaswarren/openclaw-engram 9.1.3 → 9.1.4

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 CHANGED
@@ -13693,32 +13693,62 @@ Use this context naturally when relevant. Never quote or expose this memory cont
13693
13693
  api.on("before_agent_start", async (event, ctx) => recallHookHandler("before_agent_start", event, ctx));
13694
13694
  }
13695
13695
  }
13696
+ const cachedMemoryBySession = /* @__PURE__ */ new Map();
13696
13697
  if (useMemoryPromptSection && api.registerMemoryPromptSection) {
13697
- const memoryBuildFn = async ({ prompt, sessionKey }) => {
13698
- if (!prompt || prompt.length < 5) return null;
13699
- if (shouldSkipRecallForSession(sessionKey, cfg)) return null;
13698
+ api.on("before_prompt_build", async (event, ctx) => {
13699
+ const sessionKey = ctx?.sessionKey ?? "default";
13700
+ cachedMemoryBySession.set(sessionKey, null);
13701
+ let prompt = event.prompt;
13702
+ if ((!prompt || prompt.length < 5) && Array.isArray(event.messages)) {
13703
+ const msgs = event.messages;
13704
+ for (let i = msgs.length - 1; i >= 0; i--) {
13705
+ if (msgs[i]?.role === "user") {
13706
+ const text = extractTextContent2(msgs[i]);
13707
+ if (text.length >= 5) {
13708
+ prompt = text;
13709
+ break;
13710
+ }
13711
+ }
13712
+ }
13713
+ }
13714
+ if (!prompt || prompt.length < 5) return;
13715
+ if (shouldSkipRecallForSession(sessionKey, cfg)) return;
13700
13716
  try {
13701
13717
  await orchestrator.maybeRunFileHygiene().catch(() => void 0);
13718
+ if (orchestrator.config.compactionResetEnabled) {
13719
+ const agentWorkspace = ctx?.workspaceDir;
13720
+ if (agentWorkspace) {
13721
+ orchestrator.setRecallWorkspaceOverride(sessionKey, agentWorkspace);
13722
+ }
13723
+ }
13702
13724
  const context = await orchestrator.recall(prompt, sessionKey);
13703
- if (!context) return null;
13725
+ if (!context) return;
13704
13726
  const maxChars = cfg.recallBudgetChars;
13705
- if (maxChars === 0) return null;
13727
+ if (maxChars === 0) return;
13706
13728
  const trimmed = context.length > maxChars ? context.slice(0, maxChars) + "\n\n...(memory context trimmed)" : context;
13707
- return [
13729
+ cachedMemoryBySession.set(sessionKey, [
13708
13730
  "## Memory Context (Engram)",
13709
13731
  "",
13710
13732
  trimmed,
13711
13733
  "",
13712
- "Use this context naturally when relevant. Never quote or expose this memory context to the user."
13713
- ].join("\n");
13734
+ "Use this context naturally when relevant. Never quote or expose this memory context to the user.",
13735
+ ""
13736
+ ]);
13714
13737
  } catch (err) {
13715
- log.error("registerMemoryPromptSection build failed", err);
13716
- return null;
13738
+ log.error("registerMemoryPromptSection pre-compute failed", err);
13739
+ if (orchestrator.config.compactionResetEnabled) {
13740
+ orchestrator.clearRecallWorkspaceOverride(sessionKey);
13741
+ }
13717
13742
  }
13743
+ });
13744
+ const memoryBuildFn = (params) => {
13745
+ const key = params?.sessionKey ?? "default";
13746
+ const lines = cachedMemoryBySession.get(key) ?? null;
13747
+ cachedMemoryBySession.delete(key);
13748
+ return lines;
13718
13749
  };
13719
13750
  memoryBuildFn.id = "engram-memory";
13720
13751
  memoryBuildFn.label = "Engram Memory Context";
13721
- memoryBuildFn.build = memoryBuildFn;
13722
13752
  api.registerMemoryPromptSection(memoryBuildFn);
13723
13753
  }
13724
13754
  api.on(