@memtensor/memos-local-openclaw-plugin 0.3.19 → 0.3.20

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.
Files changed (2) hide show
  1. package/index.ts +17 -1
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -1001,6 +1001,8 @@ const memosLocalPlugin = {
1001
1001
 
1002
1002
  // Track how many messages we've already processed per session to avoid
1003
1003
  // re-processing the entire conversation history on every agent_end.
1004
+ // On first encounter after restart, skip all existing messages (they were
1005
+ // already processed before the restart) and only capture future increments.
1004
1006
  const sessionMsgCursor = new Map<string, number>();
1005
1007
 
1006
1008
  api.on("agent_end", async (event) => {
@@ -1011,9 +1013,23 @@ const memosLocalPlugin = {
1011
1013
  const captureOwner = `agent:${captureAgentId}`;
1012
1014
  const sessionKey = (event as any).sessionKey ?? "default";
1013
1015
  const cursorKey = `${sessionKey}::${captureAgentId}`;
1014
- let cursor = sessionMsgCursor.get(cursorKey) ?? 0;
1015
1016
  const allMessages = event.messages;
1016
1017
 
1018
+ if (!sessionMsgCursor.has(cursorKey)) {
1019
+ // First time seeing this session after (re)start — find the last
1020
+ // user message and capture from there (current turn only).
1021
+ let lastUserIdx = -1;
1022
+ for (let i = allMessages.length - 1; i >= 0; i--) {
1023
+ const m = allMessages[i] as Record<string, unknown>;
1024
+ if (m && m.role === "user") { lastUserIdx = i; break; }
1025
+ }
1026
+ const initCursor = lastUserIdx >= 0 ? lastUserIdx : allMessages.length;
1027
+ sessionMsgCursor.set(cursorKey, initCursor);
1028
+ ctx.log.debug(`agent_end: first encounter session=${sessionKey} agent=${captureAgentId}, initialized cursor=${initCursor} (total=${allMessages.length})`);
1029
+ }
1030
+
1031
+ let cursor = sessionMsgCursor.get(cursorKey)!;
1032
+
1017
1033
  // Session was reset — cursor exceeds current message count
1018
1034
  if (cursor > allMessages.length) cursor = 0;
1019
1035
  if (cursor >= allMessages.length) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memtensor/memos-local-openclaw-plugin",
3
- "version": "0.3.19",
3
+ "version": "0.3.20",
4
4
  "description": "MemOS Local memory plugin for OpenClaw — full-write, hybrid-recall, progressive retrieval",
5
5
  "type": "module",
6
6
  "main": "index.ts",