88 */
99
1010import { Type } from "@sinclair/typebox" ;
11- import type { OpenClawPluginApi } from "openclaw/plugin-sdk/memory-core" ;
11+ import type {
12+ OpenClawPluginApi ,
13+ OpenClawPluginCliContext ,
14+ } from "openclaw/plugin-sdk/memory-core" ;
15+ import type { OpenClawPluginServiceContext } from "openclaw/plugin-sdk" ;
1216
1317import {
1418 powerMemConfigSchema ,
@@ -64,7 +68,7 @@ const memoryPlugin = {
6468 Type . Number ( { description : "Min score 0–1 to include (default: plugin recallScoreThreshold)" } ) ,
6569 ) ,
6670 } ) ,
67- async execute ( _toolCallId , params ) {
71+ async execute ( _toolCallId : string , params : Record < string , unknown > ) {
6872 const limit =
6973 typeof ( params as { limit ?: number } ) . limit === "number"
7074 ? Math . max ( 1 , Math . min ( 100 , Math . floor ( ( params as { limit : number } ) . limit ) ) )
@@ -73,6 +77,7 @@ const memoryPlugin = {
7377 typeof ( params as { scoreThreshold ?: number } ) . scoreThreshold === "number"
7478 ? Math . max ( 0 , Math . min ( 1 , ( params as { scoreThreshold : number } ) . scoreThreshold ) )
7579 : ( cfg . recallScoreThreshold ?? 0 ) ;
80+ const query = String ( ( params as { query ?: string } ) . query ?? "" ) ;
7681
7782 try {
7883 const requestLimit = Math . min ( 100 , Math . max ( limit * 2 , limit + 10 ) ) ;
@@ -136,7 +141,7 @@ const memoryPlugin = {
136141 Type . Number ( { description : "Importance 0-1 (default: 0.7)" } ) ,
137142 ) ,
138143 } ) ,
139- async execute ( _toolCallId , params ) {
144+ async execute ( _toolCallId : string , params : Record < string , unknown > ) {
140145 const { text, importance = 0.7 } = params as {
141146 text : string ;
142147 importance ?: number ;
@@ -195,7 +200,7 @@ const memoryPlugin = {
195200 query : Type . Optional ( Type . String ( { description : "Search to find memory" } ) ) ,
196201 memoryId : Type . Optional ( Type . String ( { description : "Specific memory ID" } ) ) ,
197202 } ) ,
198- async execute ( _toolCallId , params ) {
203+ async execute ( _toolCallId : string , params : Record < string , unknown > ) {
199204 const { query, memoryId } = params as { query ?: string ; memoryId ?: string } ;
200205
201206 try {
@@ -277,7 +282,7 @@ const memoryPlugin = {
277282 // ========================================================================
278283
279284 api . registerCli (
280- ( { program } ) => {
285+ ( { program } : OpenClawPluginCliContext ) => {
281286 const ltm = program
282287 . command ( "ltm" )
283288 . description ( "PowerMem long-term memory plugin commands" ) ;
@@ -287,7 +292,9 @@ const memoryPlugin = {
287292 . description ( "Search memories" )
288293 . argument ( "<query>" , "Search query" )
289294 . option ( "--limit <n>" , "Max results" , "5" )
290- . action ( async ( query : string , opts : { limit ?: string } ) => {
295+ . action ( async ( ...args : unknown [ ] ) => {
296+ const query = String ( args [ 0 ] ?? "" ) ;
297+ const opts = ( args [ 1 ] ?? { } ) as { limit ?: string } ;
291298 const limit = parseInt ( opts . limit ?? "5" , 10 ) ;
292299 const results = await client . search ( query , limit ) ;
293300 console . log ( JSON . stringify ( results , null , 2 ) ) ;
@@ -310,7 +317,8 @@ const memoryPlugin = {
310317 . command ( "add" )
311318 . description ( "Manually add a memory (for testing or one-off storage)" )
312319 . argument ( "<text>" , "Content to store" )
313- . action ( async ( text : string ) => {
320+ . action ( async ( ...args : unknown [ ] ) => {
321+ const text = String ( args [ 0 ] ?? "" ) ;
314322 try {
315323 const created = await client . add ( text . trim ( ) , { infer : cfg . inferOnAdd } ) ;
316324 if ( created . length === 0 ) {
@@ -332,15 +340,16 @@ const memoryPlugin = {
332340 // ========================================================================
333341
334342 if ( cfg . autoRecall ) {
335- api . on ( "before_agent_start" , async ( event ) => {
336- if ( ! event . prompt || event . prompt . length < 5 ) return ;
343+ api . on ( "before_agent_start" , async ( event : unknown ) => {
344+ const e = event as { prompt : string ; messages ?: unknown [ ] } ;
345+ if ( ! e . prompt || e . prompt . length < 5 ) return ;
337346
338347 const recallLimit = Math . max ( 1 , Math . min ( 100 , cfg . recallLimit ?? 5 ) ) ;
339348 const scoreThreshold = Math . max ( 0 , Math . min ( 1 , cfg . recallScoreThreshold ?? 0 ) ) ;
340349
341350 try {
342351 const requestLimit = Math . min ( 100 , Math . max ( recallLimit * 2 , recallLimit + 10 ) ) ;
343- const raw = await client . search ( event . prompt , requestLimit ) ;
352+ const raw = await client . search ( e . prompt , requestLimit ) ;
344353 const results = raw
345354 . filter ( ( r ) => ( r . score ?? 0 ) >= scoreThreshold )
346355 . slice ( 0 , recallLimit ) ;
@@ -360,14 +369,15 @@ const memoryPlugin = {
360369 }
361370
362371 if ( cfg . autoCapture ) {
363- api . on ( "agent_end" , async ( event ) => {
364- if ( ! event . success || ! event . messages || event . messages . length === 0 ) {
372+ api . on ( "agent_end" , async ( event : unknown ) => {
373+ const e = event as { messages : unknown [ ] ; success : boolean ; error ?: string } ;
374+ if ( ! e . success || ! e . messages || e . messages . length === 0 ) {
365375 return ;
366376 }
367377
368378 try {
369379 const texts : string [ ] = [ ] ;
370- for ( const msg of event . messages ) {
380+ for ( const msg of e . messages ) {
371381 if ( ! msg || typeof msg !== "object" ) continue ;
372382 const msgObj = msg as Record < string , unknown > ;
373383 const role = msgObj . role ;
@@ -433,7 +443,7 @@ const memoryPlugin = {
433443
434444 api . registerService ( {
435445 id : "memory-powermem" ,
436- start : async ( _ctx ) => {
446+ start : async ( _ctx : OpenClawPluginServiceContext ) => {
437447 try {
438448 const h = await client . health ( ) ;
439449 const where = cfg . mode === "cli" ? `cli ${ cfg . pmemPath ?? "pmem" } ` : cfg . baseUrl ;
@@ -450,7 +460,7 @@ const memoryPlugin = {
450460 ) ;
451461 }
452462 } ,
453- stop : ( _ctx ) => {
463+ stop : ( _ctx : OpenClawPluginServiceContext ) => {
454464 api . logger . info ( "memory-powermem: stopped" ) ;
455465 } ,
456466 } ) ;
0 commit comments