From 7fce9d7ec33995032aa8e02ea59e04605f24087d Mon Sep 17 00:00:00 2001 From: Prasanna A P <106952318+Prasanna721@users.noreply.github.com> Date: Wed, 17 Jun 2026 18:21:31 -0700 Subject: [PATCH 1/2] bucket capture docs by 6h utc window --- commands/slash.ts | 4 +--- hooks/capture.ts | 6 ++---- index.ts | 18 ++++-------------- memory.ts | 12 ++++++------ tools/store.ts | 4 +--- 5 files changed, 14 insertions(+), 30 deletions(-) diff --git a/commands/slash.ts b/commands/slash.ts index 64d97ab..ef9ca35 100644 --- a/commands/slash.ts +++ b/commands/slash.ts @@ -34,7 +34,6 @@ export function registerCommands( api: OpenClawPluginApi, client: SupermemoryClient, cfg: SupermemoryConfig, - getSessionKey: () => string | undefined, ): void { api.registerCommand({ name: "memory-usage", @@ -85,11 +84,10 @@ export function registerCommands( try { const category = detectCategory(text) - const sk = getSessionKey() const { status } = await client.addMemory( text, { type: category, source: "openclaw_command" }, - sk ? buildDocumentId(sk) : undefined, + buildDocumentId(), undefined, cfg.entityContext, ) diff --git a/hooks/capture.ts b/hooks/capture.ts index 7db96a8..d89d949 100644 --- a/hooks/capture.ts +++ b/hooks/capture.ts @@ -25,7 +25,6 @@ function getLastTurn(messages: unknown[]): unknown[] { export function buildCaptureHandler( client: SupermemoryClient, cfg: SupermemoryConfig, - getSessionKey: () => string | undefined, ) { return async ( event: Record, @@ -107,11 +106,10 @@ export function buildCaptureHandler( if (captured.length === 0) return const content = captured.join("\n\n") - const sk = getSessionKey() - const customId = sk ? buildDocumentId(sk) : undefined + const customId = buildDocumentId() log.debug( - `capturing ${captured.length} texts (${content.length} chars) → ${customId ?? "no-session-key"}`, + `capturing ${captured.length} texts (${content.length} chars) → ${customId}`, ) try { diff --git a/index.ts b/index.ts index 8f7511a..ac5cc18 100644 --- a/index.ts +++ b/index.ts @@ -71,22 +71,12 @@ export default { api.registerMemoryFlushPlan?.(noopFlushPlan) } - let sessionKey: string | undefined - const getSessionKey = () => sessionKey - - api.on( - "session_start", - (_event: Record, ctx: Record) => { - if (ctx.sessionKey) sessionKey = ctx.sessionKey as string - }, - ) - registerSearchTool(api, client, cfg) - registerStoreTool(api, client, cfg, getSessionKey) + registerStoreTool(api, client, cfg) registerForgetTool(api, client, cfg) registerProfileTool(api, client, cfg) registerSearchTool(api, client, cfg, "supermemory-search") - registerStoreTool(api, client, cfg, getSessionKey, "supermemory-save") + registerStoreTool(api, client, cfg, "supermemory-save") registerForgetTool(api, client, cfg, "supermemory-forget") registerProfileTool(api, client, cfg, "supermemory-profile") @@ -95,10 +85,10 @@ export default { } if (cfg.autoCapture) { - api.on("agent_end", buildCaptureHandler(client, cfg, getSessionKey)) + api.on("agent_end", buildCaptureHandler(client, cfg)) } - registerCommands(api, client, cfg, getSessionKey) + registerCommands(api, client, cfg) api.registerService({ id: "openclaw-supermemory", diff --git a/memory.ts b/memory.ts index f027ba1..7758e12 100644 --- a/memory.ts +++ b/memory.ts @@ -99,10 +99,10 @@ export function stripInboundMetadata(text: string): string { return result.join("\n").replace(/^\n+/, "").replace(/\n+$/, "") } -export function buildDocumentId(sessionKey: string): string { - const sanitized = sessionKey - .replace(/[^a-zA-Z0-9_]/g, "_") - .replace(/_+/g, "_") - .replace(/^_|_$/g, "") - return `session_${sanitized}` +export function buildDocumentId(now: Date = new Date()): string { + const yyyy = now.getUTCFullYear() + const mm = String(now.getUTCMonth() + 1).padStart(2, "0") + const dd = String(now.getUTCDate()).padStart(2, "0") + const bucket = Math.floor(now.getUTCHours() / 6) + return `session_${yyyy}-${mm}-${dd}_b${bucket}` } diff --git a/tools/store.ts b/tools/store.ts index 03b8d7b..9b3e553 100644 --- a/tools/store.ts +++ b/tools/store.ts @@ -13,7 +13,6 @@ export function registerStoreTool( api: OpenClawPluginApi, client: SupermemoryClient, cfg: SupermemoryConfig, - getSessionKey: () => string | undefined, toolName = "supermemory_store", ): void { api.registerTool( @@ -38,8 +37,7 @@ export function registerStoreTool( params: { text: string; category?: string; containerTag?: string }, ) { const category = params.category ?? detectCategory(params.text) - const sk = getSessionKey() - const customId = sk ? buildDocumentId(sk) : undefined + const customId = buildDocumentId() log.debug( `store tool: category="${category}" customId="${customId}" containerTag="${params.containerTag ?? "default"}"`, From 46a8b0c972450da1d060dd22652d3d44b2edfc27 Mon Sep 17 00:00:00 2001 From: Prasanna A P <106952318+Prasanna721@users.noreply.github.com> Date: Thu, 18 Jun 2026 16:08:59 -0700 Subject: [PATCH 2/2] fix: satisfy biome import sort and formatting in index.ts Co-Authored-By: Claude Opus 4.8 (1M context) --- index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.ts b/index.ts index ac5cc18..5b1ed3b 100644 --- a/index.ts +++ b/index.ts @@ -8,8 +8,8 @@ import { registerCommands, registerStubCommands } from "./commands/slash.ts" import { parseConfig, supermemoryConfigSchema } from "./config.ts" import { buildCaptureHandler } from "./hooks/capture.ts" import { buildRecallHandler } from "./hooks/recall.ts" -import { initLogger } from "./logger.ts" import { checkNpmUpdate, formatUpdateNotice } from "./lib/version-check.ts" +import { initLogger } from "./logger.ts" import { buildMemoryRuntime, buildPromptSection } from "./runtime.ts" import { registerForgetTool } from "./tools/forget.ts" import { registerProfileTool } from "./tools/profile.ts" @@ -17,7 +17,8 @@ import { registerSearchTool } from "./tools/search.ts" import { registerStoreTool } from "./tools/store.ts" const PLUGIN_VERSION = "2.1.14" -const UPDATE_COMMAND = "openclaw plugins install @supermemory/openclaw-supermemory" +const UPDATE_COMMAND = + "openclaw plugins install @supermemory/openclaw-supermemory" try { const stateDir =