1- import { execSync } from "child_process" ;
2- import { existsSync , readFileSync , unlinkSync , writeFileSync } from "fs" ;
1+ import { existsSync , unlinkSync , writeFileSync } from "fs" ;
32import { homedir } from "os" ;
43import { join } from "path" ;
54
65const COMPACT_FLAG = join ( homedir ( ) , ".mnemon" , ".compact-pending" ) ;
76
8- /**
9- * Extract a focused recall query from the user's prompt.
10- * Strips filler, keeps keywords — mnemon recall works best with
11- * keyword-rich queries rather than raw user prompts.
12- */
13- function extractQuery ( prompt ) {
14- if ( ! prompt || typeof prompt !== "string" ) return "" ;
15- return prompt . slice ( 0 , 200 ) . replace ( / \s + / g, " " ) . trim ( ) ;
16- }
17-
18- /**
19- * Run mnemon recall and return results, or null on failure.
20- */
21- function recall ( query ) {
22- if ( ! query ) return null ;
23- try {
24- const result = execSync (
25- `mnemon recall "${ query . replace ( / " / g, '\\"' ) } " --limit 5` ,
26- { timeout : 5000 , encoding : "utf-8" }
27- ) ;
28- if ( result && ! result . includes ( "no insights found" ) ) {
29- return result . trim ( ) ;
30- }
31- } catch {
32- // mnemon not available or recall failed — silent
33- }
34- return null ;
35- }
36-
377export default function register ( api ) {
388 // api.pluginConfig holds plugins.entries.mnemon.config from openclaw.json
399 const cfg = api . pluginConfig ?? { } ;
@@ -55,10 +25,10 @@ export default function register(api) {
5525 }
5626
5727 // ── before_prompt_build ───────────────────────────────────────
58- // Handles: remind (recall + remember reminder) + nudge reminder
59- // + compact flag consumption .
28+ // Injects reminders only — the LLM decides whether to recall/remember.
29+ // No direct mnemon execution here (CLI-in-the-loop: LLM drives the CLI) .
6030 if ( remind || nudge || compact ) {
61- api . on ( "before_prompt_build" , async ( event ) => {
31+ api . on ( "before_prompt_build" , async ( ) => {
6232 const parts = [ ] ;
6333
6434 // Compact flag: was compaction triggered since last turn?
@@ -70,11 +40,6 @@ export default function register(api) {
7040 }
7141
7242 if ( remind ) {
73- const query = extractQuery ( event . prompt ) ;
74- const memories = recall ( query ) ;
75- if ( memories ) {
76- parts . push ( `[mnemon] Relevant memories:\n${ memories } ` ) ;
77- }
7843 parts . push (
7944 "[mnemon] Evaluate: recall needed? After responding, evaluate: remember needed?"
8045 ) ;
@@ -90,11 +55,4 @@ export default function register(api) {
9055 return { prependContext : parts . join ( "\n\n" ) } ;
9156 } ) ;
9257 }
93-
94- // ── agent_end (void — no return value supported) ──────────────
95- // Placeholder for future diagnostics; memory evaluation is handled
96- // by the LLM itself via the before_prompt_build nudge above.
97- api . on ( "agent_end" , async ( ) => {
98- // no-op
99- } ) ;
10058}
0 commit comments