2026-03-17 00:14:01 -07:00
import { definePluginEntry } from "openclaw/plugin-sdk/core" ;
2026-03-18 10:43:21 +02:00
import type { MemoryPromptSectionBuilder } from "openclaw/plugin-sdk/memory-core" ;
2026-01-18 02:12:01 +00:00
2026-03-18 11:22:35 +02:00
export const buildPromptSection : MemoryPromptSectionBuilder = ( {
availableTools ,
citationsMode ,
} ) = > {
2026-03-08 11:30:34 +02:00
if ( ! availableTools . has ( "memory_search" ) && ! availableTools . has ( "memory_get" ) ) {
return [ ] ;
}
const lines = [
"## Memory Recall" ,
"Before answering anything about prior work, decisions, dates, people, preferences, or todos: run memory_search on MEMORY.md + memory/*.md; then use memory_get to pull only the needed lines. If low confidence after search, say you checked." ,
] ;
if ( citationsMode === "off" ) {
lines . push (
"Citations are disabled: do not mention file paths or line numbers in replies unless the user explicitly asks." ,
) ;
} else {
lines . push (
"Citations: include Source: <path#line> when it helps the user verify memory snippets." ,
) ;
}
lines . push ( "" ) ;
return lines ;
} ;
2026-03-17 00:14:01 -07:00
export default definePluginEntry ( {
2026-01-18 02:12:01 +00:00
id : "memory-core" ,
name : "Memory (Core)" ,
description : "File-backed memory search tools and CLI" ,
kind : "memory" ,
2026-03-17 00:14:01 -07:00
register ( api ) {
2026-03-08 11:30:34 +02:00
api . registerMemoryPromptSection ( buildPromptSection ) ;
2026-01-18 02:12:01 +00:00
api . registerTool (
( ctx ) = > {
2026-01-18 11:00:19 +00:00
const memorySearchTool = api . runtime . tools . createMemorySearchTool ( {
2026-01-18 02:12:01 +00:00
config : ctx.config ,
agentSessionKey : ctx.sessionKey ,
} ) ;
2026-01-18 11:00:19 +00:00
const memoryGetTool = api . runtime . tools . createMemoryGetTool ( {
2026-01-18 02:12:01 +00:00
config : ctx.config ,
agentSessionKey : ctx.sessionKey ,
} ) ;
2026-01-31 22:13:48 +09:00
if ( ! memorySearchTool || ! memoryGetTool ) {
return null ;
}
2026-01-18 02:12:01 +00:00
return [ memorySearchTool , memoryGetTool ] ;
} ,
{ names : [ "memory_search" , "memory_get" ] } ,
) ;
api . registerCli (
( { program } ) = > {
2026-01-18 11:00:19 +00:00
api . runtime . tools . registerMemoryCli ( program ) ;
2026-01-18 02:12:01 +00:00
} ,
{ commands : [ "memory" ] } ,
) ;
} ,
2026-03-17 00:14:01 -07:00
} ) ;