@easbot/memory 0.3.37 → 0.3.40

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 (45) hide show
  1. package/README.en.md +126 -81
  2. package/README.md +52 -36
  3. package/dist/assets/txt/src/plugin/tool/memory.txt +1 -1
  4. package/dist/chunks/{chunk-ISYAE6B7.cjs → chunk-4CMSRWL3.cjs} +12 -12
  5. package/dist/chunks/{chunk-QAEIHJOF.cjs → chunk-77ERAHDK.cjs} +16 -16
  6. package/dist/chunks/{chunk-4G4FSAFY.cjs → chunk-BHGAFQCX.cjs} +1 -1
  7. package/dist/chunks/{chunk-FZ3RTYIJ.mjs → chunk-LM6WT4CO.mjs} +11 -11
  8. package/dist/chunks/{chunk-AEAMQDNV.mjs → chunk-LQ4OZPZI.mjs} +16 -16
  9. package/dist/chunks/{chunk-YUWHNHAY.mjs → chunk-NBPDJQIR.mjs} +1 -1
  10. package/dist/chunks/cli-handler-EA6B2IET.mjs +1 -0
  11. package/dist/chunks/cli-handler-F67HXX57.cjs +1 -0
  12. package/dist/chunks/{consolidate-OOAMW7XW.mjs → consolidate-I5KIRN4Q.mjs} +1 -1
  13. package/dist/chunks/{consolidate-IKQVVWIQ.cjs → consolidate-V5B7US3A.cjs} +1 -1
  14. package/dist/chunks/{doctor-ZGHICE2Q.mjs → doctor-GYFZEOFU.mjs} +1 -1
  15. package/dist/chunks/{doctor-N6HHFR6Y.cjs → doctor-WB5IFSAX.cjs} +1 -1
  16. package/dist/chunks/{extract-7DQ6OV34.cjs → extract-NKDG4CRZ.cjs} +1 -1
  17. package/dist/chunks/{extract-AJY2ETKE.mjs → extract-PRZC6J42.mjs} +1 -1
  18. package/dist/chunks/{forget-4KGLTQ5Q.cjs → forget-HMP73OMP.cjs} +1 -1
  19. package/dist/chunks/{forget-NIBBY6FG.mjs → forget-ZETWU236.mjs} +1 -1
  20. package/dist/chunks/{graph-OG23VZZM.cjs → graph-RPU4LN35.cjs} +1 -1
  21. package/dist/chunks/{graph-4K56ZAVL.mjs → graph-XCIX6M4X.mjs} +1 -1
  22. package/dist/chunks/{init-HWR4SD6N.mjs → init-65BD6AXC.mjs} +1 -1
  23. package/dist/chunks/{init-UQTPANNI.cjs → init-EB7XE4QK.cjs} +1 -1
  24. package/dist/chunks/{mcp-ONIMP7FB.cjs → mcp-EPQG2OIZ.cjs} +1 -1
  25. package/dist/chunks/{mcp-ZWZYH52C.mjs → mcp-KUQ55KNY.mjs} +1 -1
  26. package/dist/chunks/{recall-BRXHJPR4.mjs → recall-ARCQ5XUX.mjs} +1 -1
  27. package/dist/chunks/{recall-KZRYTTWA.cjs → recall-SEYESB2W.cjs} +1 -1
  28. package/dist/chunks/{remember-GLOJH457.cjs → remember-22SZ6PPM.cjs} +1 -1
  29. package/dist/chunks/{remember-3XSYCWKK.mjs → remember-KAVRIPMH.mjs} +1 -1
  30. package/dist/chunks/{status-POX2GWSQ.cjs → status-6724XOPA.cjs} +1 -1
  31. package/dist/chunks/{status-SW5BUHJ3.mjs → status-SKORJWEX.mjs} +1 -1
  32. package/dist/chunks/stdio-server-5HTVIDF7.mjs +1 -0
  33. package/dist/chunks/{stdio-server-W52CMVJO.cjs → stdio-server-AHIGDFUH.cjs} +1 -1
  34. package/dist/chunks/{sync-I423W5G7.cjs → sync-RNULQHQD.cjs} +1 -1
  35. package/dist/chunks/{sync-EE4ZD3WB.mjs → sync-UVNIQMEQ.mjs} +1 -1
  36. package/dist/cli.cjs +1 -1
  37. package/dist/cli.mjs +1 -1
  38. package/dist/index.cjs +35 -25
  39. package/dist/index.d.cts +134 -50
  40. package/dist/index.d.ts +134 -50
  41. package/dist/index.mjs +35 -25
  42. package/package.json +11 -11
  43. package/dist/chunks/cli-handler-JHSDGJHK.mjs +0 -1
  44. package/dist/chunks/cli-handler-USK4CPAU.cjs +0 -1
  45. package/dist/chunks/stdio-server-3A3H4YJ7.mjs +0 -1
package/dist/index.cjs CHANGED
@@ -1,28 +1,38 @@
1
- 'use strict';var chunkISYAE6B7_cjs=require('./chunks/chunk-ISYAE6B7.cjs');require('./chunks/chunk-URADAZYW.cjs');var chunk4G4FSAFY_cjs=require('./chunks/chunk-4G4FSAFY.cjs'),chunkQAEIHJOF_cjs=require('./chunks/chunk-QAEIHJOF.cjs'),chunkIP7VEKQY_cjs=require('./chunks/chunk-IP7VEKQY.cjs'),chunkEKSLNNMF_cjs=require('./chunks/chunk-EKSLNNMF.cjs'),chunkAVECFV5K_cjs=require('./chunks/chunk-AVECFV5K.cjs'),chunkNHRRIJFK_cjs=require('./chunks/chunk-NHRRIJFK.cjs'),chunkGCVKM3RJ_cjs=require('./chunks/chunk-GCVKM3RJ.cjs'),chunkR32346OA_cjs=require('./chunks/chunk-R32346OA.cjs'),types=require('@easbot/types'),M=require('jieba-wasm'),utils=require('@easbot/utils'),plugin=require('@easbot/plugin'),crypto=require('crypto'),fs=require('fs'),zod=require('zod');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var M__namespace=/*#__PURE__*/_interopNamespace(M);var Sr=["user_preference","task_context","technical_fact","decision","relationship","reminder","error_pattern","workflow","exploration_finding","experience_summary","tool_usage","skill_creation","test","other"];var g=utils.Log.create({service:"memory.tokenizer"}),y=false,Be=utils.loadTextFile("./assets/jieba_dict.txt",chunkR32346OA_cjs.d);async function Gr(e){if(!y)try{g.debug("Initializing jieba tokenizer");let t=Be();if(M__namespace.with_dict(t),g.debug("Built-in dictionary loaded"),e?.dictPath&&e.dictPath.length>0)for(let o of e.dictPath)await Ye(o);y=!0,g.debug("Jieba tokenizer initialized successfully");}catch(t){g.error("Failed to initialize jieba tokenizer",{error:utils.errorMeta(t)}),g.warn("Using fallback tokenization (space-based)");}}async function Ye(e){if(!y)throw new chunkAVECFV5K_cjs.a.TokenizerNotInitializedError({message:"Tokenizer not initialized"});try{let t=await utils.Filesystem.readText(e);g.debug("Loading custom dictionary",{dictPath:e}),M__namespace.with_dict(t),g.debug("Custom dictionary loaded successfully",{dictPath:e});}catch(t){g.warn("Failed to load custom dictionary",{dictPath:e,error:utils.errorMeta(t)});}}function qe(e){if(!y)return e.split(/\s+/).filter(Boolean);try{return M__namespace.cut(e)}catch(t){return g.warn("Tokenization failed, using fallback",{error:utils.errorMeta(t)}),e.split(/\s+/).filter(Boolean)}}function je(e){if(!y)return e.split(/\s+/).filter(Boolean);try{return M__namespace.cut_for_search(e)}catch(t){return g.warn("Tokenization for search failed, using fallback",{error:utils.errorMeta(t)}),e.split(/\s+/).filter(Boolean)}}function Fr(e,t,o){if(y)try{M__namespace.add_word(e,t,o),g.debug("Word added to dictionary",{word:e,freq:t,tag:o});}catch(r){g.warn("Failed to add word",{word:e,error:utils.errorMeta(r)});}}function Dr(){return y}async function $r(){y=false,g.debug("Tokenizer closed");}function Br(e){if(!y)return e.split(/\s+/).filter(Boolean).join(" ");try{return qe(e).join(" ")}catch(t){return g.warn("Tokenization failed, using fallback",{error:utils.errorMeta(t)}),e.split(/\s+/).filter(Boolean).join(" ")}}function Yr(e){if(!y)return e.split(/\s+/).filter(Boolean).join(" ");try{return je(e).join(" ")}catch(t){return g.warn("Tokenization for search failed, using fallback",{error:utils.errorMeta(t)}),e.split(/\s+/).filter(Boolean).join(" ")}}var j="memory",K="0.3.36",v={name:j,version:K,description:"EASBot memory plugin: lifecycle hooks and memory tool",entry:"./index.mjs",capabilities:["hooks","tools"]};function f(e,t){if(typeof e!="object"||e===null)return;let o=e;for(let r of t){let l=o[r];if(typeof l=="string"&&l.length>0)return l}}function me(e){if(typeof e!="object"||e===null)return {};let t=e.extras;return typeof t=="object"&&t!==null&&!Array.isArray(t)?t:{}}function ce(e){if(typeof e!="object"||e===null)return;let t=e.protocolMetadata;if(typeof t!="object"||t===null)return;let o=t.agentId;return typeof o=="string"&&o.length>0?o:void 0}function b(e,t){let o={...me(e),...me(t)};return {agentId:f(t,["agentId"])??ce(e)??ce(t)??f(e,["agentId"])??f(t,["agent"])??f(e,["agent"])??"",sessionId:f(t,["sessionId"])??f(e,["sessionId"]),toolName:f(e,["toolName","tool","name"])??f(t,["toolName"]),error:f(e,["error","message"])??f(t,["error"]),messagePreview:f(e,["messagePreview"])??f(t,["messagePreview"]),contextPreview:f(e,["contextPreview","text","prompt"])??f(t,["contextPreview"]),extras:o}}function h(e){let t=chunkGCVKM3RJ_cjs.f().worktree,o=chunkGCVKM3RJ_cjs.j(t),r=e.trim()||"memory-plugin";return {agentId:r,isTrustedLocal:true,remote:false,locale:"en-US",dbPath:o,workspaceDir:t,rootDir:t,config:chunkQAEIHJOF_cjs.A({agentId:r,dbPath:o,workspaceDir:t})}}function u(e,t){return {modified:false,input:e,output:{...t}}}function de(e,t){return {modified:true,input:e,output:{...t}}}function pe(e,t){return f(e,[t])}var We=utils.Log.create({service:"memory.plugin.hook"}),C=async(e,t)=>{let o=plugin.HookEvent.ContextBuildBefore,r=b(e,t);if(!r.agentId.trim())return u(e,{hook:o,ok:false,error:"context build: agentId is required"});let l=typeof r.extras.topK=="number"?r.extras.topK:5,c=typeof r.extras.query=="string"?r.extras.query:"";try{let d=await chunkQAEIHJOF_cjs.z("recall",{query:c,maxResults:l},h(r.agentId));if(d.hits.length===0)return u(e,{hook:o,ok:!0,context:[],logLine:"context build: no facts found; skipping context injection"});let i=d.hits.map($=>`- [${$.category}/imp=${$.importance}] ${$.snippet.slice(0,200)}`),a=`[memory:recall top-${d.hits.length}]
2
- ${i.join(`
3
- `)}`,x=pe(e,"userMessage");return x===void 0?u(e,{hook:o,ok:!0,context:[a],logLine:`context build: recalled ${d.hits.length} facts (input shape unexpected, not injected)`}):de({...e,userMessage:x?`${a}
1
+ 'use strict';var chunk4CMSRWL3_cjs=require('./chunks/chunk-4CMSRWL3.cjs');require('./chunks/chunk-URADAZYW.cjs');var chunkBHGAFQCX_cjs=require('./chunks/chunk-BHGAFQCX.cjs'),chunk77ERAHDK_cjs=require('./chunks/chunk-77ERAHDK.cjs'),chunkIP7VEKQY_cjs=require('./chunks/chunk-IP7VEKQY.cjs'),chunkEKSLNNMF_cjs=require('./chunks/chunk-EKSLNNMF.cjs'),chunkAVECFV5K_cjs=require('./chunks/chunk-AVECFV5K.cjs'),chunkNHRRIJFK_cjs=require('./chunks/chunk-NHRRIJFK.cjs'),chunkGCVKM3RJ_cjs=require('./chunks/chunk-GCVKM3RJ.cjs'),chunkR32346OA_cjs=require('./chunks/chunk-R32346OA.cjs'),types=require('@easbot/types'),k=require('jieba-wasm'),utils=require('@easbot/utils'),plugin=require('@easbot/plugin'),crypto=require('crypto'),llm=require('@easbot/llm'),ai=require('ai'),fs=require('fs'),terminal=require('@easbot/terminal'),zod=require('zod');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var k__namespace=/*#__PURE__*/_interopNamespace(k);var nr=["user_preference","task_context","technical_fact","decision","relationship","reminder","error_pattern","workflow","exploration_finding","experience_summary","tool_usage","skill_creation","test","other"];var f=utils.Log.create({service:"memory.tokenizer"}),I=false,gt=utils.loadTextFile("./assets/jieba_dict.txt",chunkR32346OA_cjs.d);async function ur(e){if(!I)try{f.debug("Initializing jieba tokenizer");let r=gt();if(k__namespace.with_dict(r),f.debug("Built-in dictionary loaded"),e?.dictPath&&e.dictPath.length>0)for(let t of e.dictPath)await ft(t);I=!0,f.debug("Jieba tokenizer initialized successfully");}catch(r){f.error("Failed to initialize jieba tokenizer",{error:utils.errorMeta(r)}),f.warn("Using fallback tokenization (space-based)");}}async function ft(e){if(!I)throw new chunkAVECFV5K_cjs.a.TokenizerNotInitializedError({message:"Tokenizer not initialized"});try{let r=await utils.Filesystem.readText(e);f.debug("Loading custom dictionary",{dictPath:e}),k__namespace.with_dict(r),f.debug("Custom dictionary loaded successfully",{dictPath:e});}catch(r){f.warn("Failed to load custom dictionary",{dictPath:e,error:utils.errorMeta(r)});}}function yt(e){if(!I)return e.split(/\s+/).filter(Boolean);try{return k__namespace.cut(e)}catch(r){return f.warn("Tokenization failed, using fallback",{error:utils.errorMeta(r)}),e.split(/\s+/).filter(Boolean)}}function Mt(e){if(!I)return e.split(/\s+/).filter(Boolean);try{return k__namespace.cut_for_search(e)}catch(r){return f.warn("Tokenization for search failed, using fallback",{error:utils.errorMeta(r)}),e.split(/\s+/).filter(Boolean)}}function gr(e,r,t){if(I)try{k__namespace.add_word(e,r,t),f.debug("Word added to dictionary",{word:e,freq:r,tag:t});}catch(o){f.warn("Failed to add word",{word:e,error:utils.errorMeta(o)});}}function fr(){return I}async function yr(){I=false,f.debug("Tokenizer closed");}function Mr(e){if(!I)return e.split(/\s+/).filter(Boolean).join(" ");try{return yt(e).join(" ")}catch(r){return f.warn("Tokenization failed, using fallback",{error:utils.errorMeta(r)}),e.split(/\s+/).filter(Boolean).join(" ")}}function xr(e){if(!I)return e.split(/\s+/).filter(Boolean).join(" ");try{return Mt(e).join(" ")}catch(r){return f.warn("Tokenization for search failed, using fallback",{error:utils.errorMeta(r)}),e.split(/\s+/).filter(Boolean).join(" ")}}var Q="memory",J="0.3.39",$={name:Q,version:J,description:"EASBot memory plugin: lifecycle hooks and memory tool",entry:"./index.mjs",capabilities:["hooks","tools"]};async function h(){return chunkNHRRIJFK_cjs.d.exists()}function y(e,r){if(typeof e!="object"||e===null)return;let t=e;for(let o of r){let n=t[o];if(typeof n=="string"&&n.length>0)return n}}function ke(e){if(typeof e!="object"||e===null)return {};let r=e.extras;return typeof r=="object"&&r!==null&&!Array.isArray(r)?r:{}}function he(e){if(typeof e!="object"||e===null)return;let r=e.protocolMetadata;if(typeof r!="object"||r===null)return;let t=r.agentId;return typeof t=="string"&&t.length>0?t:void 0}function S(e,r){let t={...ke(e),...ke(r)};return {agentId:y(r,["agentId"])??he(e)??he(r)??y(e,["agentId"])??y(r,["agent"])??y(e,["agent"])??"",sessionId:y(r,["sessionId"])??y(e,["sessionId"]),toolName:y(e,["toolName","tool","name"])??y(r,["toolName"]),error:y(e,["error","message"])??y(r,["error"]),messagePreview:y(e,["messagePreview"])??y(r,["messagePreview"]),contextPreview:y(e,["contextPreview","text","prompt"])??y(r,["contextPreview"]),extras:t}}function H(e){let r=chunkGCVKM3RJ_cjs.f().worktree,t=chunkGCVKM3RJ_cjs.j(r),o=e.trim()||"memory-plugin";return {agentId:o,isTrustedLocal:true,remote:false,locale:"en-US",dbPath:t,workspaceDir:r,rootDir:r,config:chunk77ERAHDK_cjs.A({agentId:o,dbPath:t,workspaceDir:r})}}function M(e,r){return {modified:false,input:e,output:{...r}}}function _e(e,r){return y(e,[r])}var X=utils.Log.create({service:"memory.plugin.hook"}),we=1200;function kt(e,r){let t=e;for(let n of [t?.query,r.query])if(typeof n=="string"&&n.trim().length>0)return n;return _e(e,"userMessage")??""}var G=async(e,r)=>{let t=plugin.HookEvent.ContextCollect,o=S(e,r);if(!o.agentId.trim())return {modified:false,input:e,output:{hook:t,ok:false,error:"context collect: agentId is required",fragments:[]}};if(!await h())return X.debug("context.collect: memory not configured, skip recall"),{modified:false,input:e,output:{hook:t,ok:true,fragments:[],logLine:"memory not configured"}};let n=typeof o.extras.topK=="number"?o.extras.topK:5,d=kt(e,o.extras);if(d.trim().length===0)return X.debug("context.collect: empty query, skip recall"),{modified:false,input:e,output:{hook:t,ok:true,fragments:[],logLine:"context collect: empty query"}};try{let c=await chunk77ERAHDK_cjs.z("recall",{query:d,maxResults:n},H(o.agentId));if(c.hits.length===0)return {modified:!1,input:e,output:{hook:t,ok:!0,fragments:[],logLine:"context collect: no facts found"}};let m=c.hits.map(i=>`- [${i.category}/imp=${i.importance}] ${i.snippet}`).join(`
2
+ `),s=await utils.TruncateContent.truncate(m,{maxChars:Math.min(we*4,utils.TruncateContent.DEFAULT_MAX_CHARS),label:"memory recall fragments"}),a={id:"memory:recall",title:"Relevant Memory",content:s.content,source:"memory",order:10,markers:["<memory-recall>","</memory-recall>"]};return {modified:!1,input:e,output:{hook:t,ok:!0,fragments:[a],logLine:`context collect: contributed ${c.hits.length} facts${s.truncated?" (truncated; full content saved for agent read-back)":""}`}}}catch(c){let m=utils.errorMeta(c);return X.warn("memory context collect hook failed",{error:m}),{modified:false,input:e,output:{hook:t,ok:false,error:m.message,fragments:[]}}}};var Re=utils.Log.create({service:"memory.plugin.hook"}),wt=200,Y=async(e,r)=>{let t=plugin.HookEvent.SessionCompacting,o=S(e,r);if(!o.agentId.trim())return M(e,{hook:t,ok:false,error:"pre compact: agentId is required"});if(!await h())return Re.debug("pre-compact: memory not configured, skip recall"),M(e,{hook:t,ok:true,context:[],logLine:"memory not configured"});let d=(o.contextPreview??o.messagePreview??"").slice(0,wt).replace(/\s+/g," ").trim(),c=typeof o.extras.topK=="number"?o.extras.topK:3;if(!d)return M(e,{hook:t,ok:true,context:[],logLine:"pre compact: empty context preview; skipping recall injection"});try{let m=await chunk77ERAHDK_cjs.z("recall",{query:d,maxResults:c,minImportance:5},H(o.agentId));if(m.hits.length===0)return M(e,{hook:t,ok:!0,context:[],logLine:"pre compact: no facts matched query"});let s=m.hits.map(i=>`- [${i.category}/imp=${i.importance}] ${i.snippet.slice(0,150)}`),a=`[memory:pre-compact recall top-${m.hits.length} (imp>=5)]
3
+ ${s.join(`
4
+ `)}`;return M(e,{hook:t,ok:!0,context:[a],logLine:`pre compact: injected ${m.hits.length} facts before compaction`})}catch(m){let s=utils.errorMeta(m);return Re.warn("memory pre compact hook failed",{error:s}),M(e,{hook:t,ok:false,error:s.message})}};var Oe=utils.Log.create({service:"memory.plugin.hook"}),Pt=8,j=async(e,r)=>{let t=plugin.HookEvent.ToolFailure,o=S(e,r);if(!o.agentId.trim())return M(e,{hook:t,ok:false,error:"tool failure: agentId is required"});if(!o.toolName?.trim()||!o.error?.trim())return M(e,{hook:t,ok:false,error:"tool failure: toolName and error are required"});if(!await h())return Oe.debug("tool.failure: memory not configured, skip remember"),M(e,{hook:t,ok:true,logLine:"memory not configured"});let n=crypto.createHash("sha256").update(`${o.toolName}:${o.error}`).digest("hex").slice(0,Pt),d=o.messagePreview?o.messagePreview.slice(0,200).replace(/\s+/g," ").trim():"",c=[`[error_pattern] tool=${o.toolName}`,`[error] ${o.error}`,d?`[preview] ${d}`:"",`[errHash] ${n}`].filter(Boolean).join(`
5
+ `);try{let m=await chunk77ERAHDK_cjs.z("remember",{content:c,category:"error_pattern",importance:6,tags:["post-tool-failure",`tool:${o.toolName}`,`err:${n}`],sessionId:o.sessionId,msgId:typeof o.extras.msgId=="string"?o.extras.msgId:void 0},H(o.agentId));return M(e,{hook:t,ok:!0,logLine:`tool failure: wrote error_pattern fact ${m.fact.id} (tool=${o.toolName}, errHash=${n})`})}catch(m){let s=utils.errorMeta(m);return Oe.warn("memory tool failure hook failed",{error:s}),M(e,{hook:t,ok:false,error:s.message})}};var b=utils.Log.create({service:"memory.plugin.extract"}),Se=2e3,Dt=4096,He="memory",Pe=["memory","read","glob","grep"];function Ft(e){return (e??[]).filter(r=>r.type==="text"&&!r.synthetic&&!r.ignored).map(r=>r.text??"").join("")}async function $t(e,r){let t=[];for(let n of await e.messagesByParent(r)){if(n.role!=="assistant")continue;let d=n.parts.filter(c=>c.type==="text").map(c=>c.text??"").join("");d&&t.push({role:"assistant",content:d});}let o=await e.message(r);if(o&&o.role==="user"){let n=Ft(o.parts);n&&t.push({role:"user",content:n});}return t}async function Gt(e){if(e.length===0)return "";let r=`### Our Conversation
4
6
 
5
- ${x}`:a},{hook:o,ok:!0,context:[a],logLine:`context build: injected ${d.hits.length} facts`})}catch(d){let i=utils.errorMeta(d);return We.warn("memory context build hook failed",{error:i}),u(e,{hook:o,ok:false,error:i.message})}};var Xe=utils.Log.create({service:"memory.plugin.hook"}),Ze=200,A=async(e,t)=>{let o=plugin.HookEvent.SessionCompacting,r=b(e,t);if(!r.agentId.trim())return u(e,{hook:o,ok:false,error:"pre compact: agentId is required"});let c=(r.contextPreview??r.messagePreview??"").slice(0,Ze).replace(/\s+/g," ").trim(),d=typeof r.extras.topK=="number"?r.extras.topK:3;if(!c)return u(e,{hook:o,ok:true,context:[],logLine:"pre compact: empty context preview; skipping recall injection"});try{let i=await chunkQAEIHJOF_cjs.z("recall",{query:c,maxResults:d,minImportance:5},h(r.agentId));if(i.hits.length===0)return u(e,{hook:o,ok:!0,context:[],logLine:"pre compact: no facts matched query"});let a=i.hits.map(N=>`- [${N.category}/imp=${N.importance}] ${N.snippet.slice(0,150)}`),x=`[memory:pre-compact recall top-${i.hits.length} (imp>=5)]
6
- ${a.join(`
7
- `)}`;return u(e,{hook:o,ok:!0,context:[x],logLine:`pre compact: injected ${i.hits.length} facts before compaction`})}catch(i){let a=utils.errorMeta(i);return Xe.warn("memory pre compact hook failed",{error:a}),u(e,{hook:o,ok:false,error:a.message})}};var nr=utils.Log.create({service:"memory.plugin.hook"}),ar=8,L=async(e,t)=>{let o=plugin.HookEvent.ToolFailure,r=b(e,t);if(!r.agentId.trim())return u(e,{hook:o,ok:false,error:"tool failure: agentId is required"});if(!r.toolName?.trim()||!r.error?.trim())return u(e,{hook:o,ok:false,error:"tool failure: toolName and error are required"});let l=crypto.createHash("sha256").update(`${r.toolName}:${r.error}`).digest("hex").slice(0,ar),c=r.messagePreview?r.messagePreview.slice(0,200).replace(/\s+/g," ").trim():"",d=[`[error_pattern] tool=${r.toolName}`,`[error] ${r.error}`,c?`[preview] ${c}`:"",`[errHash] ${l}`].filter(Boolean).join(`
8
- `);try{let i=await chunkQAEIHJOF_cjs.z("remember",{content:d,category:"error_pattern",importance:6,tags:["post-tool-failure",`tool:${r.toolName}`,`err:${l}`],sessionId:r.sessionId,msgId:typeof r.extras.msgId=="string"?r.extras.msgId:void 0},h(r.agentId));return u(e,{hook:o,ok:!0,logLine:`tool failure: wrote error_pattern fact ${i.fact.id} (tool=${r.toolName}, errHash=${l})`})}catch(i){let a=utils.errorMeta(i);return nr.warn("memory tool failure hook failed",{error:a}),u(e,{hook:o,ok:false,error:a.message})}};var I=[{event:plugin.HookEvent.ContextBuildBefore,handler:C},{event:plugin.HookEvent.SessionCompacting,handler:A},{event:plugin.HookEvent.ToolFailure,handler:L}];function E(){return I.map(({event:e,handler:t})=>({event:e,hooks:[{type:"function",handler:t}]}))}var S=utils.Log.create({service:"memory.plugin.tool"}),W="memory",G=["recall","remember","update","forget","extract","graph_query","status"],pr=500,ue="Access EASBot long-term memory via `operation` (recall / remember / update / forget / extract / graph_query / status).",F=zod.z.enum(["user_preference","task_context","technical_fact","decision","relationship","reminder","error_pattern","workflow","exploration_finding","experience_summary","tool_usage","skill_creation","test","other"]),ur=zod.z.object({operation:zod.z.literal("recall"),query:zod.z.string().describe("Search query text"),limit:utils.Schema.positiveInt.optional().default(10).describe("Max results (default 10)"),category:F.optional().describe("Filter by memory category"),minImportance:utils.Schema.positiveInt.optional().refine(e=>e===void 0||e>=1&&e<=10,{message:"minImportance must be in [1, 10] (inclusive); the service uses `WHERE importance >= ?` SQL"}).describe("INCLUSIVE `>=` filter on 1-10 importance scale"),maxEdgesPerNode:utils.Schema.positiveInt.optional().default(10).refine(e=>e===void 0||e>=1&&e<=100,{message:"maxEdgesPerNode must be in [1, 100]"}).describe("Max edges per KG neighbor node returned by recall (default 10; range [1, 100])"),includeGraph:zod.z.boolean().optional().default(false).describe("Include KG neighbor subgraph (default false)"),includeShared:zod.z.boolean().optional().default(false).describe("Include shared KG nodes from other agents (default false)")}).strict(),gr=zod.z.object({operation:zod.z.literal("remember"),content:zod.z.string().describe("Memory content"),category:F.describe("Memory category"),importance:utils.Schema.positiveInt.describe("Importance 1-10 (service layer enforces range)"),tags:utils.Schema.stringArray.optional().describe("Optional tags (string[])")}).strict(),fr=zod.z.object({operation:zod.z.literal("update"),factId:zod.z.string().describe("Target fact id (must belong to ctx.agentId)"),content:zod.z.string().optional().describe("New content (triggers embedding rewrite + FTS reindex)"),category:F.optional().describe("New category"),importance:utils.Schema.positiveInt.optional().describe("New importance 1-10"),tags:utils.Schema.stringArray.optional().describe("New tags (string[]; empty array clears tags)")}).strict().refine(e=>e.content!==void 0||e.category!==void 0||e.importance!==void 0||e.tags!==void 0,{message:"update requires at least one of: `content`, `category`, `importance`, `tags`"}),yr=zod.z.object({operation:zod.z.literal("forget"),factId:zod.z.string().describe("Target fact id to delete (must belong to ctx.agentId)"),dryRun:zod.z.boolean().optional().default(false).describe("Preview without deleting (returns matched count, never deletes)"),force:zod.z.boolean().optional().default(false).describe("Skip KG reference check and delete anyway (use after dryRun confirms the match)")}).strict(),Mr=zod.z.object({operation:zod.z.literal("extract"),lastN:utils.Schema.positiveInt.optional().default(10).describe("Recent messages (default 10)"),fromMessageId:zod.z.string().optional().describe("Process messages after this id")}).strict(),xr=zod.z.object({operation:zod.z.literal("graph_query"),query:zod.z.string().min(1).optional().describe('Node name fragment (NOT natural-language query): locate one root node by case-insensitive `LIKE %name%` match against `nodes.name`, then BFS neighbor expansion. Pass only short identifiers (e.g. "easbot"). Use `recall` for natural-language fact search.'),nodeId:utils.Schema.positiveInt.optional().describe("KG node id to start BFS from (alternative to `query`)"),maxDepth:utils.Schema.positiveInt.optional().default(2).describe("BFS depth for neighbor expansion (default 2; range [1, 5])"),maxNodes:utils.Schema.nonNegativeInt.optional().default(100).describe("Max nodes returned after BFS (default 100; service max 500)"),maxEdgesPerNode:utils.Schema.positiveInt.optional().default(10).refine(e=>e===void 0||e>=1&&e<=100,{message:"maxEdgesPerNode must be in [1, 100]"}).describe("Max edges per BFS neighbor node (default 10; range [1, 100])"),relation:zod.z.string().optional().describe('Edge relation filter (e.g. "uses"; single-value exact match)'),type:zod.z.string().optional().describe('Node type filter for root node (e.g. "decision")')}).strict().refine(e=>e.query!==void 0||e.nodeId!==void 0,{message:"graph_query requires either `query` (node name fragment) or `nodeId` (KG node id)"}),kr=zod.z.object({operation:zod.z.literal("status")}).strict(),br={recall:ur,remember:gr,update:fr,forget:yr,extract:Mr,graph_query:xr,status:kr},D={operation:zod.z.enum(G).describe("Operation to run (exactly one per call)"),query:zod.z.string().optional().describe("recall: search query text / graph_query: node name fragment"),limit:utils.Schema.positiveInt.optional().describe("recall: max results (default 10, max 100)"),category:F.optional().describe("remember/update: memory category / recall: category filter"),minImportance:utils.Schema.positiveInt.optional().describe("recall: INCLUSIVE `>=` filter on the 1-10 importance scale"),maxEdgesPerNode:utils.Schema.positiveInt.optional().describe("recall/graph_query: max edges per KG neighbor node (default 10, max 100)"),includeGraph:zod.z.boolean().optional().describe("recall: include KG neighbor subgraph (default false)"),includeShared:zod.z.boolean().optional().describe("recall: include shared KG nodes from other agents (default false)"),content:zod.z.string().optional().describe("remember/update: fact body"),importance:utils.Schema.positiveInt.optional().describe("remember/update: importance 1-10"),tags:utils.Schema.stringArray.optional().describe("remember/update: tags (string[] or comma-separated string)"),factId:zod.z.string().optional().describe("update/forget: target fact id"),dryRun:zod.z.boolean().optional().describe("forget: preview without deleting (default false)"),force:zod.z.boolean().optional().describe("forget: skip KG reference check and delete anyway (default false)"),lastN:utils.Schema.positiveInt.optional().describe("extract: recent messages to scan (default 10)"),fromMessageId:zod.z.string().optional().describe("extract: process messages after this id"),nodeId:utils.Schema.positiveInt.optional().describe("graph_query: KG node id to start BFS from"),maxDepth:utils.Schema.positiveInt.optional().describe("graph_query: BFS depth (default 2, max 5)"),maxNodes:utils.Schema.nonNegativeInt.optional().describe("graph_query: max nodes returned after BFS (default 100, max 500)"),relation:zod.z.string().optional().describe("graph_query: edge relation filter (single-value exact match)"),type:zod.z.string().optional().describe("graph_query: node type filter for root node")};function hr(){try{let e=utils.loadTextFile("./memory.txt",chunkR32346OA_cjs.d)();return e.trim().length>0?e:ue}catch(e){return S.warn("memory tool description unavailable, using fallback",{error:utils.errorMeta(e)}),ue}}function Ir(e){let t=e.agent?.trim();if(!t)throw new utils.NameErrors.MissingFieldError({message:"memory tool: agentId is required (ctx.agent must be set)",field:"agentId"});return t}function _r(e,t){let o=br[e],r={};for(let c of Object.keys(o.shape))r[c]=t[c];let l=o.safeParse({...r,operation:e});if(!l.success){let c=l.error.issues.map(d=>`${d.path.join(".")||"(root)"}: ${d.message}`).join("; ");throw new utils.NameErrors.InvalidArgumentError({message:`memory tool: invalid parameters for operation "${e}" \u2014 ${c}`,param:e})}return l.data}async function Or(e,t){let o=chunkGCVKM3RJ_cjs.j(e);if(!fs.existsSync(o)){S.debug("memory db not found, auto-initializing",{dbPath:o,workspaceDir:e});try{await chunkQAEIHJOF_cjs.z("init",{workspaceDir:e,force:!1},t);}catch(r){throw new utils.NameErrors.OperationFailedError({message:`memory tool: auto-init failed (${utils.errorMeta(r).message}). Try running \`easbot memory init\` manually.`,operation:"memory-auto-init"})}}}async function Rr(){if(!(chunkEKSLNNMF_cjs.a.isInitialized()&&chunkEKSLNNMF_cjs.a.capabilities().graph))try{let e=await chunkNHRRIJFK_cjs.d.getMemoryJson();chunkEKSLNNMF_cjs.a.init({models:{embedding:e?.embedding_model??void 0,graph:e?.graph_model??void 0}});}catch(e){S.warn("memory Llm init failed; KG extraction will be skipped",{error:utils.errorMeta(e)});}}var w=plugin.createTool({description:hr(),args:D,execute:async(e,t)=>{let o=String(e.operation);try{await t.ask({permission:"memory",patterns:o==="recall"?[String(e.query??"")]:["*"],always:["*"],metadata:{operation:o}});let r=_r(o,e),l=Ir(t),c=t.worktree||t.directory||process.cwd(),d=chunkGCVKM3RJ_cjs.j(c),i={agentId:l,isTrustedLocal:!0,remote:!1,locale:"en-US",dbPath:d,workspaceDir:c,rootDir:c,config:chunkQAEIHJOF_cjs.A({agentId:l,dbPath:d,workspaceDir:c}),signal:t.abort};switch(await Rr(),await Or(c,i),o){case "recall":{let a=await chunkQAEIHJOF_cjs.z("recall",{query:r.query,maxResults:r.limit,category:r.category,minImportance:r.minImportance,maxEdgesPerNode:r.maxEdgesPerNode,includeGraph:r.includeGraph,includeShared:r.includeShared,snippetMaxChars:pr},i);return await chunkISYAE6B7_cjs.a("recall",a,{toolName:"memory_recall",query:r.query,agentId:l,scope:r.includeShared?"both":"agent_only"})}case "remember":{let a=await chunkQAEIHJOF_cjs.z("remember",{content:r.content,category:r.category,importance:r.importance,tags:r.tags,sessionId:t.sessionId},i);return `<memory_result>
7
+ `;for(let t of e){let o=utils.Token.estimate(t.content),n=t.content,d=false;if(o>Se){n=t.content.slice(-8e3),d=true;}d?r+=`**${t.role==="user"?"User":"Me"}**: ${n}
8
+
9
+ [Content truncated from ${o} tokens]
10
+
11
+ `:r+=`**${t.role==="user"?"User":"Me"}**: ${n||"(empty)"}
12
+
13
+ `;}return r}async function Yt(){let r=(await llm.Agent.get(He))?.prompt?.trim();if(!r)throw new Error(`memory extract: agent "${He}" has no prompt (\u8BB0\u5FC6\u89C4\u8303\u7F3A\u5931)`);return r}async function jt(e,r,t,o,n){let d=o.agent||await llm.Agent.defaultAgent(),c=d?await llm.Agent.get(d):void 0;if(!c)throw new Error(`memory extract: agent not found (${d})`);let m=o.model??await llm.Provider.defaultModel(),s=typeof m=="string"?llm.Provider.parseModel(m):m,a=await llm.Provider.getModel(s.providerId,s.modelId),i=await t.get();if(!i)throw new Error(`memory extract: session not found (${e.sessionId})`);let p=r.identity?.();if(!p)throw new Error("memory extract: identity capability unavailable");let{metadata:v,initialized:_}=await p.protocol(),se=i.contextMode??types.DefaultContextMode,De=await Yt(),Fe=await p.staticPrompt({agent:c,model:{providerId:a.providerId,modelId:a.api?.id??a.id},workspaceDir:i.directory,mode:se}),$e=await p.environment({agent:c,model:{providerId:a.providerId,modelId:a.api?.id??a.id},mode:se}),Ge=[utils.Markdown.replaceVariables(De,v),...Fe.map(z=>z.content),...$e],Ye=await t.tools({agent:c.name,model:{providerId:a.providerId,modelId:a.api?.id??a.id},toolFilter:z=>Pe.includes(z)}),je=`Review the conversation below and decide what is worth remembering. Store it with the \`memory\` tool.
14
+
15
+ ${await Gt(n)}`,ie=await llm.LanguageProvider.generate({user:{id:utils.Identifier.ascending("message"),sessionId:e.sessionId,model:o.model??{providerId:a.providerId,modelId:a.api?.id??a.id}},sessionId:e.sessionId,agent:c,system:Ge,model:a,temperature:llm.Provider.LIMITS.TEMPERATURE.SUMMARY,maxOutputTokens:Dt,messages:[{role:"user",content:[{type:"text",text:je}]}],tools:Ye,activeTools:Pe,stopWhen:ai.stepCountIs(5),abort:new AbortController().signal});return b.debug("memory extract finished",{sessionId:e.sessionId,outputLength:ie.text.length}),ie.text}async function Z(e,r,t,o,n){try{await e.updatePart({...t,messageId:r,status:n.status,time:{start:o,end:Date.now()},...n.result!==void 0?{result:n.result}:{},...n.error!==void 0?{error:n.error}:{},...n.reason!==void 0?{reason:n.reason}:{}});}catch(d){b.error("memory part status update failed",{error:utils.errorMeta(d),status:n.status});}}async function Te(e,r){let t=e;if(!t.userMessageId)return b.debug("loop.end: no userMessageId, skip"),{modified:false,input:e};if(!await h())return b.debug("loop.end: memory not configured, skip extract"),{modified:false,input:e};let o=`${t.sessionId}:${t.userMessageId}`;if(b.debug("loop.end: memory extract started",{loopKey:o,step:t.step,result:t.result}),r.agent&&await llm.Agent.isSubagent(r.agent))return b.debug("loop.end: skip memory extract, subagent",{loopKey:o}),{modified:false,input:e};let n=r.session?.(t.sessionId);if(!n)return b.debug("loop.end: skip memory extract, session capability unavailable",{loopKey:o}),{modified:false,input:e};let d=await n.message(t.userMessageId);if(!d)return b.debug("loop.end: user message not found, skip",{loopKey:o}),{modified:false,input:e};if(d.parts.some(p=>p.type==="memory"))return b.debug("loop.end: skip memory extract, already processed"),{modified:false,input:e};let c=utils.Identifier.ascending("part"),m=Date.now(),s={id:c,type:"memory",status:"in_progress",time:{start:m}};await n.updatePart({...s,messageId:t.userMessageId});let a=await $t(n,t.userMessageId);return a.some(p=>p.role==="assistant"&&p.content)?(jt(t,r,n,d,a).then(p=>Z(n,t.userMessageId,s,m,{status:"completed",result:p})).catch(p=>(b.error("memory extract failed",{error:utils.errorMeta(p)}),Z(n,t.userMessageId,s,m,{status:"failed",error:utils.errorMeta(p).message}))),{modified:false,input:e}):(b.debug("loop.end: skip memory extract, no assistant text content",{loopKey:o}),await Z(n,t.userMessageId,s,m,{status:"skipped",reason:"No assistant text content"}),{modified:false,input:e})}var w=[{event:plugin.HookEvent.ContextCollect,handler:G},{event:plugin.HookEvent.SessionCompacting,handler:Y},{event:plugin.HookEvent.ToolFailure,handler:j},{event:plugin.HookEvent.LoopEnd,handler:Te}];function N(){return w.map(({event:e,handler:r})=>({event:e,hooks:[{type:"function",handler:r}]}))}var A=utils.Log.create({service:"memory.plugin.tool"}),oe="memory",ne=["recall","remember","update","forget","extract","graph_query","status"],Jt=500,Ce="Access EASBot long-term memory via `operation` (recall / remember / update / forget / extract / graph_query / status).",te=zod.z.enum(["user_preference","task_context","technical_fact","decision","relationship","reminder","error_pattern","workflow","exploration_finding","experience_summary","tool_usage","skill_creation","test","other"]),Ne=zod.z.discriminatedUnion("operation",[zod.z.object({operation:zod.z.literal("recall"),query:zod.z.string().describe("Search query text"),limit:utils.Schema.positiveInt.optional().default(10).describe("Max results (default 10)"),category:te.optional().describe("Filter by memory category"),minImportance:utils.Schema.positiveInt.optional().refine(e=>e===void 0||e>=1&&e<=10,{message:"minImportance must be in [1, 10] (inclusive); the service uses `WHERE importance >= ?` SQL"}).describe("INCLUSIVE `>=` filter on 1-10 importance scale; e.g. `5` keeps importance 5"),minScore:zod.z.number().min(0).max(1).optional().describe("Minimum relevance score filter (default 0; range [0, 1])"),maxEdgesPerNode:utils.Schema.positiveInt.optional().default(10).refine(e=>e===void 0||e>=1&&e<=100,{message:"maxEdgesPerNode must be in [1, 100]"}).describe("Max edges per KG neighbor node returned by recall (default 10; range [1, 100])"),includeGraph:zod.z.boolean().optional().default(false).describe("Include KG neighbor subgraph (default false; pass true to get BFS neighbors alongside hits)"),includeShared:zod.z.boolean().optional().default(false).describe("Include shared KG nodes from other agents (requires trusted local; default false)")}).strict(),zod.z.object({operation:zod.z.literal("remember"),content:zod.z.string().describe("Memory content"),category:te.describe("Memory category"),importance:utils.Schema.positiveInt.describe("Importance 1-10 (service layer enforces range)"),tags:utils.Schema.stringArray.optional().describe("Optional tags (string[])")}).strict(),zod.z.object({operation:zod.z.literal("update"),factId:zod.z.string().describe("Target fact id (must belong to ctx.agentId)"),content:zod.z.string().optional().describe("New content (triggers embedding rewrite + FTS reindex)"),category:te.optional().describe("New category"),importance:utils.Schema.positiveInt.optional().describe("New importance 1-10"),tags:utils.Schema.stringArray.optional().describe("New tags (string[]; empty array clears tags)")}).strict().refine(e=>e.content!==void 0||e.category!==void 0||e.importance!==void 0||e.tags!==void 0,{message:"update requires at least one of: `content`, `category`, `importance`, `tags`"}),zod.z.object({operation:zod.z.literal("forget"),factId:zod.z.string().describe("Target fact id to delete (required; must belong to ctx.agentId)"),dryRun:zod.z.boolean().optional().default(false).describe("Preview without deleting (returns matched count, never deletes)"),force:zod.z.boolean().optional().default(false).describe("Skip KG reference check and delete anyway (required when fact is referenced by other facts; use after dryRun confirms the match)")}).strict(),zod.z.object({operation:zod.z.literal("extract"),lastN:utils.Schema.positiveInt.optional().default(10).describe("Recent messages (default 10)"),fromMessageId:zod.z.string().optional().describe("Process messages after this id")}).strict(),zod.z.object({operation:zod.z.literal("graph_query"),nodeId:utils.Schema.positiveInt.describe("KG node ID to start BFS from; get it from a recall hit or a prior graph_query result"),maxDepth:utils.Schema.positiveInt.optional().default(2).describe("BFS depth for neighbor expansion (default 2; service range [1, 5])"),maxNodes:utils.Schema.nonNegativeInt.optional().default(100).describe("Max nodes returned after BFS (default 100; service max 500)"),maxEdgesPerNode:utils.Schema.positiveInt.optional().default(10).refine(e=>e===void 0||e>=1&&e<=100,{message:"maxEdgesPerNode must be in [1, 100]"}).describe("Max edges per BFS neighbor node (default 10; range [1, 100])"),relation:zod.z.string().optional().describe('Edge relation filter (e.g. "uses"; single-value exact match; differs from note.graph_query relationTypes[])'),type:zod.z.string().optional().describe('Node type filter for root node (e.g. "decision"; only affects CLI query path; nodeId path bypasses)')}).strict(),zod.z.object({operation:zod.z.literal("status")}).strict()]),ae=Ne;function Xt(){try{let e=utils.loadTextFile("./memory.txt",chunkR32346OA_cjs.d)();return e.trim().length>0?e:Ce}catch(e){return A.warn("memory tool description unavailable, using fallback",{error:utils.errorMeta(e)}),Ce}}function Zt(e){let r=e.agent?.trim();if(!r)throw new utils.NameErrors.MissingFieldError({message:"memory tool: agentId is required (ctx.agent must be set)",field:"agentId"});return r}function er(e){if(e?.sessionId?.trim())return e.sessionId;throw new utils.NameErrors.MissingFieldError({message:"memory tool: sessionId is required (ctx.sessionId must be set)",field:"sessionId"})}async function tr(e,r){let t=chunkGCVKM3RJ_cjs.j(e);if(!fs.existsSync(t)){A.debug("memory db not found, auto-initializing",{dbPath:t,workspaceDir:e});try{await chunk77ERAHDK_cjs.z("init",{workspaceDir:e,force:!1},r);}catch(o){throw new utils.NameErrors.OperationFailedError({message:`memory tool: auto-init failed (${utils.errorMeta(o).message}). Try running \`easbot memory init\` manually.`,operation:"memory-auto-init"})}}}async function rr(){if(!(chunkEKSLNNMF_cjs.a.isInitialized()&&chunkEKSLNNMF_cjs.a.capabilities().graph))try{let e=await chunkNHRRIJFK_cjs.d.getMemoryJson();chunkEKSLNNMF_cjs.a.init({models:{embedding:e?.embedding_model??void 0,graph:e?.graph_model??void 0}});}catch(e){A.warn("memory Llm init failed; KG extraction will be skipped",{error:utils.errorMeta(e)});}}var L=plugin.createTool({description:Xt(),args:Ne,isEnabled:()=>chunkNHRRIJFK_cjs.d.exists(),execute:async(e,r)=>{let t=e,o=t.operation;try{await r.ask({permission:"memory",patterns:o==="recall"?[t.query]:["*"],always:["*"],metadata:{operation:o}});let n=Zt(r),d=r.worktree||r.directory||process.cwd(),c=chunkGCVKM3RJ_cjs.j(d),m={agentId:n,isTrustedLocal:!0,remote:!1,locale:utils.Locale.resolveLocaleLang(),dbPath:c,workspaceDir:d,rootDir:d,config:chunk77ERAHDK_cjs.A({agentId:n,dbPath:c,workspaceDir:d}),signal:r.abort};switch(await rr(),await tr(d,m),o){case "recall":{let s=await chunk77ERAHDK_cjs.z("recall",{query:t.query,maxResults:t.limit,category:t.category,minImportance:t.minImportance,minScore:t.minScore,maxEdgesPerNode:t.maxEdgesPerNode,includeGraph:t.includeGraph??!1,includeShared:t.includeShared??!1,snippetMaxChars:Jt},m);return {output:await chunk4CMSRWL3_cjs.a("recall",{kind:"recall",query:t.query,agentId:m.agentId,scope:"agent_only",totalCount:s.total,truncated:s.truncated,hits:s.hits.map(i=>({fact:{id:i.memoryId,agentId:i.agentId,category:i.category,content:i.content,importance:i.importance,tags:i.tags??null,source:i.source,sessionId:i.sessionId??null,msgId:i.msgId??null,parentMsgId:i.parentMsgId??null,filePath:i.filePath??null,createdAt:i.createdAt,updatedAt:i.updatedAt??i.createdAt,truncated:i.content.length>200},score:i.score,source:"hybrid",snippet:i.snippet,nodeIds:i.nodes?.map(p=>p.id)??[],nodes:i.nodes}))},{toolName:"memory_recall"}),title:`Memory: recall (${t.query})`,metadata:{operation:"recall",enabled:!0,agentId:n,query:t.query}}}case "remember":{let s=await chunk77ERAHDK_cjs.z("remember",{content:t.content,category:t.category,importance:t.importance,tags:t.tags,sessionId:r.sessionId},m);return {output:`<memory_result>
9
16
  Memory saved.
10
- id: ${a.fact.id}
11
- category: ${a.fact.category}
12
- importance: ${r.importance}
13
- linked nodes: ${a.nodeIds?.length??0}
14
- </memory_result>`}case "update":{let a=await chunkQAEIHJOF_cjs.z("update",{factId:r.factId,content:r.content,category:r.category,importance:r.importance,tags:r.tags},i),x=a.fieldsUpdated?.join(", ")??"none";return `<memory_result>
17
+ id: ${s.fact.id}
18
+ category: ${s.fact.category}
19
+ importance: ${t.importance}
20
+ linked nodes: ${s.nodeIds?.length??0}
21
+ </memory_result>`,title:"Memory saved",metadata:{operation:"remember",enabled:!0,agentId:n,memoryId:s.fact.id,category:s.fact.category,importance:t.importance}}}case "update":{let s=await chunk77ERAHDK_cjs.z("update",{factId:t.factId,content:t.content,category:t.category,importance:t.importance,tags:t.tags},m),a=s.fieldsUpdated.length>0?s.fieldsUpdated.join(", "):"(no-op)",i=s.contentChanged?" (embedding rewritten)":"";return {output:`<memory_result>
15
22
  Memory updated.
16
- id: ${r.factId}
17
- updated fields: ${x}
18
- content changed: ${a.contentChanged}
19
- </memory_result>`}case "forget":{let a=await chunkQAEIHJOF_cjs.z("forget",{factId:r.factId,dryRun:r.dryRun,force:r.force},i);return await chunkISYAE6B7_cjs.a("forget",a)}case "extract":{let a=await chunkQAEIHJOF_cjs.z("extract",{sessionId:t.sessionId,lastN:r.lastN,fromMessageId:r.fromMessageId},i);return `<memory_result>
20
- Extraction finished.
21
- extracted: ${a.extractedCount??0}
22
- entities: ${a.entities?.length??0}
23
- relations: ${a.relations?.length??0}
24
- </memory_result>`}case "graph_query":{let a=await chunkQAEIHJOF_cjs.z("graph_query",{query:r.query,nodeId:r.nodeId,maxDepth:r.maxDepth,maxNodes:r.maxNodes,maxEdgesPerNode:r.maxEdgesPerNode,relation:r.relation,type:r.type},i);return await chunkISYAE6B7_cjs.a("graph_query",a)}case "status":{let a=await chunkQAEIHJOF_cjs.z("status",{},i);return await chunkISYAE6B7_cjs.a("status",a)}}}catch(r){if(r instanceof utils.ServiceError)try{return utils.ServiceErrorBus.toMarkdown(r,{tool:"memory",operation:o,resultTag:"<memory_result>",pack:"memory"})}catch(l){return S.error("memory tool ServiceErrorBus formatting failed",{error:utils.errorMeta(l)}),`<memory_result>
25
- Error: ${r.message}
26
- </memory_result>`}return S.error("memory tool execution failed",{operation:o,error:utils.errorMeta(r)}),`<memory_result>
27
- Error: ${utils.errorMeta(r).message}
28
- </memory_result>`}}});var P=async e=>({hooks:E(),tools:{[v.name]:w}});utils.Log.create({service:"memory.plugin.hook"});var ge=[plugin.HookEvent.ContextBuildBefore,plugin.HookEvent.SessionCompacting,plugin.HookEvent.ToolFailure];var fe={name:"memory.plugin",async init(){return {isEnabled:()=>true,handlers:I.map(({event:e,handler:t})=>({name:e,handler:t}))}}};Object.defineProperty(exports,"MemoryStdioServer",{enumerable:true,get:function(){return chunkISYAE6B7_cjs.b}});Object.defineProperty(exports,"renderOperationMarkdown",{enumerable:true,get:function(){return chunkISYAE6B7_cjs.a}});Object.defineProperty(exports,"COMMANDS_HELP",{enumerable:true,get:function(){return chunk4G4FSAFY_cjs.a}});Object.defineProperty(exports,"handleMemoryCli",{enumerable:true,get:function(){return chunk4G4FSAFY_cjs.d}});Object.defineProperty(exports,"renderBanner",{enumerable:true,get:function(){return chunk4G4FSAFY_cjs.b}});Object.defineProperty(exports,"renderHelp",{enumerable:true,get:function(){return chunk4G4FSAFY_cjs.c}});Object.defineProperty(exports,"ALL_OPS",{enumerable:true,get:function(){return chunkQAEIHJOF_cjs.y}});Object.defineProperty(exports,"GraphStore",{enumerable:true,get:function(){return chunkQAEIHJOF_cjs.a}});Object.defineProperty(exports,"OP_REGISTRY",{enumerable:true,get:function(){return chunkQAEIHJOF_cjs.x}});Object.defineProperty(exports,"consolidate",{enumerable:true,get:function(){return chunkQAEIHJOF_cjs.r}});Object.defineProperty(exports,"doctor",{enumerable:true,get:function(){return chunkQAEIHJOF_cjs.v}});Object.defineProperty(exports,"executeOp",{enumerable:true,get:function(){return chunkQAEIHJOF_cjs.z}});Object.defineProperty(exports,"extract",{enumerable:true,get:function(){return chunkQAEIHJOF_cjs.q}});Object.defineProperty(exports,"forget",{enumerable:true,get:function(){return chunkQAEIHJOF_cjs.p}});Object.defineProperty(exports,"graphQuery",{enumerable:true,get:function(){return chunkQAEIHJOF_cjs.t}});Object.defineProperty(exports,"init",{enumerable:true,get:function(){return chunkQAEIHJOF_cjs.w}});Object.defineProperty(exports,"recall",{enumerable:true,get:function(){return chunkQAEIHJOF_cjs.b}});Object.defineProperty(exports,"remember",{enumerable:true,get:function(){return chunkQAEIHJOF_cjs.n}});Object.defineProperty(exports,"status",{enumerable:true,get:function(){return chunkQAEIHJOF_cjs.u}});Object.defineProperty(exports,"sync",{enumerable:true,get:function(){return chunkQAEIHJOF_cjs.s}});Object.defineProperty(exports,"update",{enumerable:true,get:function(){return chunkQAEIHJOF_cjs.o}});Object.defineProperty(exports,"LATEST_SCHEMA_VERSION",{enumerable:true,get:function(){return chunkIP7VEKQY_cjs.a}});Object.defineProperty(exports,"MIGRATIONS",{enumerable:true,get:function(){return chunkIP7VEKQY_cjs.b}});Object.defineProperty(exports,"MemoryDatabaseManager",{enumerable:true,get:function(){return chunkIP7VEKQY_cjs.e}});Object.defineProperty(exports,"readCurrentSchemaVersion",{enumerable:true,get:function(){return chunkIP7VEKQY_cjs.d}});Object.defineProperty(exports,"runMigrations",{enumerable:true,get:function(){return chunkIP7VEKQY_cjs.c}});Object.defineProperty(exports,"Llm",{enumerable:true,get:function(){return chunkEKSLNNMF_cjs.a}});Object.defineProperty(exports,"DEFAULT_MEMORY_JSON",{enumerable:true,get:function(){return chunkNHRRIJFK_cjs.b}});Object.defineProperty(exports,"MEMORY_JSON_REL_PATH",{enumerable:true,get:function(){return chunkNHRRIJFK_cjs.c}});Object.defineProperty(exports,"MemoryCache",{enumerable:true,get:function(){return chunkNHRRIJFK_cjs.d}});Object.defineProperty(exports,"MemoryJsonSchema",{enumerable:true,get:function(){return chunkNHRRIJFK_cjs.a}});Object.defineProperty(exports,"getGlobal",{enumerable:true,get:function(){return chunkGCVKM3RJ_cjs.c}});Object.defineProperty(exports,"getHomeDir",{enumerable:true,get:function(){return chunkGCVKM3RJ_cjs.g}});Object.defineProperty(exports,"getInstance",{enumerable:true,get:function(){return chunkGCVKM3RJ_cjs.f}});Object.defineProperty(exports,"getMemoryDbPath",{enumerable:true,get:function(){return chunkGCVKM3RJ_cjs.j}});Object.defineProperty(exports,"getMemoryDir",{enumerable:true,get:function(){return chunkGCVKM3RJ_cjs.i}});Object.defineProperty(exports,"getXdgData",{enumerable:true,get:function(){return chunkGCVKM3RJ_cjs.h}});Object.defineProperty(exports,"resetGlobalAdapter",{enumerable:true,get:function(){return chunkGCVKM3RJ_cjs.b}});Object.defineProperty(exports,"resetInstanceAdapter",{enumerable:true,get:function(){return chunkGCVKM3RJ_cjs.e}});Object.defineProperty(exports,"setGlobalAdapter",{enumerable:true,get:function(){return chunkGCVKM3RJ_cjs.a}});Object.defineProperty(exports,"setInstanceAdapter",{enumerable:true,get:function(){return chunkGCVKM3RJ_cjs.d}});Object.defineProperty(exports,"GRAPH_ENTITY_TYPE_DEFINITIONS",{enumerable:true,get:function(){return types.GRAPH_ENTITY_TYPE_DEFINITIONS}});Object.defineProperty(exports,"GRAPH_RELATION_TYPE_DEFINITIONS",{enumerable:true,get:function(){return types.GRAPH_RELATION_TYPE_DEFINITIONS}});exports.MEMORY_CATEGORIES=Sr;exports.MEMORY_HOOK_BINDINGS=I;exports.MEMORY_HOOK_EVENTS=ge;exports.MEMORY_PLUGIN_ID=j;exports.MEMORY_PLUGIN_MANIFEST=v;exports.MEMORY_PLUGIN_VERSION=K;exports.MEMORY_TOOL_ARGS=D;exports.MEMORY_TOOL_ID=W;exports.MEMORY_TOOL_OPS=G;exports.MemoryPlugin=P;exports.MemoryPluginEntry=P;exports.MemoryPluginHook=fe;exports.MemoryTool=w;exports.addWord=Fr;exports.closeTokenizer=$r;exports.createMemoryHookMatchers=E;exports.initTokenizer=Gr;exports.isInitialized=Dr;exports.loadCustomDict=Ye;exports.toFtsTokens=Br;exports.toFtsTokensForSearch=Yr;exports.tokenize=qe;exports.tokenizeForSearch=je;
23
+ id: ${s.fact.id}
24
+ category: ${s.fact.category}
25
+ importance: ${s.fact.importance}
26
+ fields updated: ${a}${i}
27
+ updated_at: ${s.fact.updatedAt}
28
+ </memory_result>`,title:"Memory updated",metadata:{operation:"update",enabled:!0,agentId:n,memoryId:s.fact.id,category:s.fact.category,importance:s.fact.importance}}}case "forget":{let s=await chunk77ERAHDK_cjs.z("forget",{factId:t.factId,dryRun:t.dryRun,force:t.force},m);return {output:await chunk4CMSRWL3_cjs.a("forget",s,{toolName:"memory_forget"}),title:"Memory: forget",metadata:{operation:"forget",enabled:!0,agentId:n}}}case "extract":{let s=er(r),a=await chunk77ERAHDK_cjs.z("extract",{sessionId:s,lastN:t.lastN,fromMessageId:t.fromMessageId},m);return {output:`<memory_result>
29
+ Extract completed.
30
+ sessionId: ${s}
31
+ extractedCount: ${a.extractedCount}
32
+ factIds: ${a.factIds.length>0?a.factIds.join(", "):"(none)"}
33
+ messageRange: ${a.messageRange.fromMessageId} -> ${a.messageRange.toMessageId}
34
+ </memory_result>`,title:"memory: extract",metadata:{operation:"extract",enabled:!0,agentId:n,total:a.extractedCount}}}case "graph_query":{let s=await chunk77ERAHDK_cjs.z("graph_query",{nodeId:t.nodeId,maxDepth:t.maxDepth,maxNodes:t.maxNodes,maxEdgesPerNode:t.maxEdgesPerNode,...t.relation!==void 0?{relation:t.relation}:{},...t.type!==void 0?{type:t.type}:{}},m);return {output:await chunk4CMSRWL3_cjs.a("graph_query",s,{toolName:"memory_graph_query"}),title:"Memory: graph_query",metadata:{operation:"graph_query",enabled:!0,agentId:n}}}case "status":{let a=await chunk77ERAHDK_cjs.z("status",{},m);return {output:terminal.renderKnowledgeStatus({packageName:"memory",rootDir:a.workspaceDir??"",configPath:a.configPath??"",configExists:typeof a.configExists=="boolean"?a.configExists:!0,dbPath:a.dbPath,dbExists:typeof a.dbExists=="boolean"?a.dbExists:!0,dbSize:a.dbSize,indexState:a.indexState,schemaVersion:a.schemaVersion,extractionVersion:a.extractionVersion,lastSyncAt:a.lastSyncAt,vectorEnabled:a.vectorEnabled,embeddingDims:a.embeddingDims,llm:a.llm??{initialized:!1,capabilities:{}},backend:a.backend,healthy:a.healthy,recommendation:a.recommendation,dbStats:a.dbStats??a.integrityStats,extras:(()=>{let p={};if(typeof a.agentId=="string"&&(p.agent_id=a.agentId),typeof a.ftsAvailable=="boolean"&&(p.fts_available=a.ftsAvailable?"yes":"no"),a.factsByCategory&&typeof a.factsByCategory=="object")for(let[v,_]of Object.entries(a.factsByCategory))typeof _=="number"&&_>0&&(p[`facts/${v}`]=_);if(a.meta&&typeof a.meta=="object")for(let[v,_]of Object.entries(a.meta))_!==void 0&&(p[`meta/${v}`]=_);return Object.keys(p).length>0?p:void 0})()}),title:"Memory: status",metadata:{operation:"status",enabled:!0,agentId:n}}}}}catch(n){if(utils.ServiceError.isInstance(n))try{return {output:utils.ServiceErrorBus.toMarkdown(n,{tool:"memory",operation:o,resultTag:"<memory_result>",pack:"memory"}),title:`Memory: ${o} (${n.data.code})`,metadata:{operation:o,enabled:!0,businessErrorCode:n.data.code}}}catch(d){return A.error("memory tool ServiceErrorBus formatting failed",{error:utils.errorMeta(d)}),{output:`<memory_result>
35
+ Error: ${n.data.message}
36
+ </memory_result>`,title:`Memory: ${o} (${n.data.code})`,metadata:{operation:o,enabled:true,businessErrorCode:n.data.code}}}return A.error("memory tool execution failed",{operation:o,error:utils.errorMeta(n)}),{output:`<memory_result>
37
+ Error: ${utils.errorMeta(n).message}
38
+ </memory_result>`,title:`Memory: ${o} (error)`,metadata:{operation:o,enabled:true}}}}});var D=async e=>({hooks:N(),tools:{[$.name]:L}});var Ae=[plugin.HookEvent.ContextCollect,plugin.HookEvent.SessionCompacting,plugin.HookEvent.ToolFailure,plugin.HookEvent.LoopEnd];var Le={name:"memory.plugin",async init(){return {isEnabled:()=>true,handlers:w.map(({event:e,handler:r})=>({name:e,handler:r}))}}};Object.defineProperty(exports,"MemoryStdioServer",{enumerable:true,get:function(){return chunk4CMSRWL3_cjs.b}});Object.defineProperty(exports,"renderOperationMarkdown",{enumerable:true,get:function(){return chunk4CMSRWL3_cjs.a}});Object.defineProperty(exports,"COMMANDS_HELP",{enumerable:true,get:function(){return chunkBHGAFQCX_cjs.a}});Object.defineProperty(exports,"handleMemoryCli",{enumerable:true,get:function(){return chunkBHGAFQCX_cjs.d}});Object.defineProperty(exports,"renderBanner",{enumerable:true,get:function(){return chunkBHGAFQCX_cjs.b}});Object.defineProperty(exports,"renderHelp",{enumerable:true,get:function(){return chunkBHGAFQCX_cjs.c}});Object.defineProperty(exports,"ALL_OPS",{enumerable:true,get:function(){return chunk77ERAHDK_cjs.y}});Object.defineProperty(exports,"GraphStore",{enumerable:true,get:function(){return chunk77ERAHDK_cjs.a}});Object.defineProperty(exports,"OP_REGISTRY",{enumerable:true,get:function(){return chunk77ERAHDK_cjs.x}});Object.defineProperty(exports,"consolidate",{enumerable:true,get:function(){return chunk77ERAHDK_cjs.r}});Object.defineProperty(exports,"doctor",{enumerable:true,get:function(){return chunk77ERAHDK_cjs.v}});Object.defineProperty(exports,"executeOp",{enumerable:true,get:function(){return chunk77ERAHDK_cjs.z}});Object.defineProperty(exports,"extract",{enumerable:true,get:function(){return chunk77ERAHDK_cjs.q}});Object.defineProperty(exports,"forget",{enumerable:true,get:function(){return chunk77ERAHDK_cjs.p}});Object.defineProperty(exports,"graphQuery",{enumerable:true,get:function(){return chunk77ERAHDK_cjs.t}});Object.defineProperty(exports,"init",{enumerable:true,get:function(){return chunk77ERAHDK_cjs.w}});Object.defineProperty(exports,"recall",{enumerable:true,get:function(){return chunk77ERAHDK_cjs.b}});Object.defineProperty(exports,"remember",{enumerable:true,get:function(){return chunk77ERAHDK_cjs.n}});Object.defineProperty(exports,"status",{enumerable:true,get:function(){return chunk77ERAHDK_cjs.u}});Object.defineProperty(exports,"sync",{enumerable:true,get:function(){return chunk77ERAHDK_cjs.s}});Object.defineProperty(exports,"update",{enumerable:true,get:function(){return chunk77ERAHDK_cjs.o}});Object.defineProperty(exports,"LATEST_SCHEMA_VERSION",{enumerable:true,get:function(){return chunkIP7VEKQY_cjs.a}});Object.defineProperty(exports,"MIGRATIONS",{enumerable:true,get:function(){return chunkIP7VEKQY_cjs.b}});Object.defineProperty(exports,"MemoryDatabaseManager",{enumerable:true,get:function(){return chunkIP7VEKQY_cjs.e}});Object.defineProperty(exports,"readCurrentSchemaVersion",{enumerable:true,get:function(){return chunkIP7VEKQY_cjs.d}});Object.defineProperty(exports,"runMigrations",{enumerable:true,get:function(){return chunkIP7VEKQY_cjs.c}});Object.defineProperty(exports,"Llm",{enumerable:true,get:function(){return chunkEKSLNNMF_cjs.a}});Object.defineProperty(exports,"DEFAULT_MEMORY_JSON",{enumerable:true,get:function(){return chunkNHRRIJFK_cjs.b}});Object.defineProperty(exports,"MEMORY_JSON_REL_PATH",{enumerable:true,get:function(){return chunkNHRRIJFK_cjs.c}});Object.defineProperty(exports,"MemoryCache",{enumerable:true,get:function(){return chunkNHRRIJFK_cjs.d}});Object.defineProperty(exports,"MemoryJsonSchema",{enumerable:true,get:function(){return chunkNHRRIJFK_cjs.a}});Object.defineProperty(exports,"getGlobal",{enumerable:true,get:function(){return chunkGCVKM3RJ_cjs.c}});Object.defineProperty(exports,"getHomeDir",{enumerable:true,get:function(){return chunkGCVKM3RJ_cjs.g}});Object.defineProperty(exports,"getInstance",{enumerable:true,get:function(){return chunkGCVKM3RJ_cjs.f}});Object.defineProperty(exports,"getMemoryDbPath",{enumerable:true,get:function(){return chunkGCVKM3RJ_cjs.j}});Object.defineProperty(exports,"getMemoryDir",{enumerable:true,get:function(){return chunkGCVKM3RJ_cjs.i}});Object.defineProperty(exports,"getXdgData",{enumerable:true,get:function(){return chunkGCVKM3RJ_cjs.h}});Object.defineProperty(exports,"resetGlobalAdapter",{enumerable:true,get:function(){return chunkGCVKM3RJ_cjs.b}});Object.defineProperty(exports,"resetInstanceAdapter",{enumerable:true,get:function(){return chunkGCVKM3RJ_cjs.e}});Object.defineProperty(exports,"setGlobalAdapter",{enumerable:true,get:function(){return chunkGCVKM3RJ_cjs.a}});Object.defineProperty(exports,"setInstanceAdapter",{enumerable:true,get:function(){return chunkGCVKM3RJ_cjs.d}});Object.defineProperty(exports,"GRAPH_ENTITY_TYPE_DEFINITIONS",{enumerable:true,get:function(){return types.GRAPH_ENTITY_TYPE_DEFINITIONS}});Object.defineProperty(exports,"GRAPH_RELATION_TYPE_DEFINITIONS",{enumerable:true,get:function(){return types.GRAPH_RELATION_TYPE_DEFINITIONS}});exports.MEMORY_CATEGORIES=nr;exports.MEMORY_HOOK_BINDINGS=w;exports.MEMORY_HOOK_EVENTS=Ae;exports.MEMORY_PLUGIN_ID=Q;exports.MEMORY_PLUGIN_MANIFEST=$;exports.MEMORY_PLUGIN_VERSION=J;exports.MEMORY_TOOL_ARGS=ae;exports.MEMORY_TOOL_ID=oe;exports.MEMORY_TOOL_OPS=ne;exports.MemoryPlugin=D;exports.MemoryPluginEntry=D;exports.MemoryPluginHook=Le;exports.MemoryTool=L;exports.addWord=gr;exports.closeTokenizer=yr;exports.createMemoryHookMatchers=N;exports.initTokenizer=ur;exports.isInitialized=fr;exports.loadCustomDict=ft;exports.toFtsTokens=Mr;exports.toFtsTokensForSearch=xr;exports.tokenize=yt;exports.tokenizeForSearch=Mt;
package/dist/index.d.cts CHANGED
@@ -2,7 +2,7 @@ import * as _easbot_types from '@easbot/types';
2
2
  import { KnowledgeSearchOptions, MemoryKnowledgeConfigWithModels, KnowledgeDoctorResult, MemoryStatus, IGlobal, IInstance } from '@easbot/types';
3
3
  export { GRAPH_ENTITY_TYPE_DEFINITIONS, GRAPH_RELATION_TYPE_DEFINITIONS } from '@easbot/types';
4
4
  import { ILLMInitConfig, ILLMCapabilities, EmbeddingModelRef, LanguageModelRef, ExtractedEntity, ExtractedRelation } from '@easbot/llm';
5
- import { z, ZodTypeAny } from 'zod';
5
+ import { z, ZodType } from 'zod';
6
6
  import { StdioServerConfig } from '@easbot/mcp';
7
7
  import { SyncSqliteConnection } from '@easbot/database';
8
8
  import { Plugin, PluginManifest, HookMatcher, HookHandler, HookInfo } from '@easbot/plugin';
@@ -446,7 +446,7 @@ interface OpHandlerContext {
446
446
  remote?: boolean;
447
447
  config?: unknown;
448
448
  }
449
- interface MemoryOp<TSchema extends ZodTypeAny | undefined = undefined, TResult = unknown> {
449
+ interface MemoryOp<TSchema extends ZodType | undefined = undefined, TResult = unknown> {
450
450
  name: string;
451
451
  scope: OpScope;
452
452
  schema?: TSchema;
@@ -638,12 +638,12 @@ declare namespace MemoryCache {
638
638
  declare const MemoryPlugin: Plugin;
639
639
 
640
640
  declare const MEMORY_PLUGIN_ID = "memory";
641
- declare const MEMORY_PLUGIN_VERSION = "0.3.36";
641
+ declare const MEMORY_PLUGIN_VERSION = "0.3.39";
642
642
  declare const MEMORY_PLUGIN_MANIFEST: PluginManifest;
643
643
 
644
644
  declare function createMemoryHookMatchers(): HookMatcher[];
645
645
 
646
- declare const MEMORY_HOOK_EVENTS: readonly ["context.build.before", "session.compacting", "tool.failure"];
646
+ declare const MEMORY_HOOK_EVENTS: readonly ["context.collect", "session.compacting", "tool.failure", "loop.end"];
647
647
  type MemoryHookEvent = (typeof MEMORY_HOOK_EVENTS)[number];
648
648
  type MemoryHookHandler = HookHandler<unknown>;
649
649
 
@@ -658,18 +658,10 @@ declare const MemoryPluginHook: HookInfo;
658
658
  declare const MEMORY_TOOL_ID = "memory";
659
659
  declare const MEMORY_TOOL_OPS: readonly ["recall", "remember", "update", "forget", "extract", "graph_query", "status"];
660
660
  type MemoryToolOperation = (typeof MEMORY_TOOL_OPS)[number];
661
- declare const MEMORY_TOOL_ARGS: {
662
- operation: z.ZodEnum<{
663
- status: "status";
664
- recall: "recall";
665
- forget: "forget";
666
- graph_query: "graph_query";
667
- remember: "remember";
668
- update: "update";
669
- extract: "extract";
670
- }>;
671
- query: z.ZodOptional<z.ZodString>;
672
- limit: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>;
661
+ declare const MEMORY_TOOL_ARGS: z.ZodDiscriminatedUnion<[z.ZodObject<{
662
+ operation: z.ZodLiteral<"recall">;
663
+ query: z.ZodString;
664
+ limit: z.ZodDefault<z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>>;
673
665
  category: z.ZodOptional<z.ZodEnum<{
674
666
  user_preference: "user_preference";
675
667
  task_context: "task_context";
@@ -687,36 +679,78 @@ declare const MEMORY_TOOL_ARGS: {
687
679
  other: "other";
688
680
  }>>;
689
681
  minImportance: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>;
690
- maxEdgesPerNode: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>;
691
- includeGraph: z.ZodOptional<z.ZodBoolean>;
692
- includeShared: z.ZodOptional<z.ZodBoolean>;
682
+ minScore: z.ZodOptional<z.ZodNumber>;
683
+ maxEdgesPerNode: z.ZodDefault<z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>>;
684
+ includeGraph: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
685
+ includeShared: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
686
+ }, z.core.$strict>, z.ZodObject<{
687
+ operation: z.ZodLiteral<"remember">;
688
+ content: z.ZodString;
689
+ category: z.ZodEnum<{
690
+ user_preference: "user_preference";
691
+ task_context: "task_context";
692
+ technical_fact: "technical_fact";
693
+ decision: "decision";
694
+ relationship: "relationship";
695
+ reminder: "reminder";
696
+ error_pattern: "error_pattern";
697
+ workflow: "workflow";
698
+ exploration_finding: "exploration_finding";
699
+ experience_summary: "experience_summary";
700
+ tool_usage: "tool_usage";
701
+ skill_creation: "skill_creation";
702
+ test: "test";
703
+ other: "other";
704
+ }>;
705
+ importance: z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>;
706
+ tags: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodString]>, z.ZodTransform<string[], string | string[]>>, z.ZodArray<z.ZodString>>>;
707
+ }, z.core.$strict>, z.ZodObject<{
708
+ operation: z.ZodLiteral<"update">;
709
+ factId: z.ZodString;
693
710
  content: z.ZodOptional<z.ZodString>;
711
+ category: z.ZodOptional<z.ZodEnum<{
712
+ user_preference: "user_preference";
713
+ task_context: "task_context";
714
+ technical_fact: "technical_fact";
715
+ decision: "decision";
716
+ relationship: "relationship";
717
+ reminder: "reminder";
718
+ error_pattern: "error_pattern";
719
+ workflow: "workflow";
720
+ exploration_finding: "exploration_finding";
721
+ experience_summary: "experience_summary";
722
+ tool_usage: "tool_usage";
723
+ skill_creation: "skill_creation";
724
+ test: "test";
725
+ other: "other";
726
+ }>>;
694
727
  importance: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>;
695
728
  tags: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodString]>, z.ZodTransform<string[], string | string[]>>, z.ZodArray<z.ZodString>>>;
696
- factId: z.ZodOptional<z.ZodString>;
697
- dryRun: z.ZodOptional<z.ZodBoolean>;
698
- force: z.ZodOptional<z.ZodBoolean>;
699
- lastN: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>;
729
+ }, z.core.$strict>, z.ZodObject<{
730
+ operation: z.ZodLiteral<"forget">;
731
+ factId: z.ZodString;
732
+ dryRun: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
733
+ force: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
734
+ }, z.core.$strict>, z.ZodObject<{
735
+ operation: z.ZodLiteral<"extract">;
736
+ lastN: z.ZodDefault<z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>>;
700
737
  fromMessageId: z.ZodOptional<z.ZodString>;
701
- nodeId: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>;
702
- maxDepth: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>;
703
- maxNodes: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>;
738
+ }, z.core.$strict>, z.ZodObject<{
739
+ operation: z.ZodLiteral<"graph_query">;
740
+ nodeId: z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>;
741
+ maxDepth: z.ZodDefault<z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>>;
742
+ maxNodes: z.ZodDefault<z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>>;
743
+ maxEdgesPerNode: z.ZodDefault<z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>>;
704
744
  relation: z.ZodOptional<z.ZodString>;
705
745
  type: z.ZodOptional<z.ZodString>;
706
- };
746
+ }, z.core.$strict>, z.ZodObject<{
747
+ operation: z.ZodLiteral<"status">;
748
+ }, z.core.$strict>], "operation">;
707
749
  declare const MemoryTool: _easbot_types.ToolDefinition & {
708
- args: {
709
- operation: z.ZodEnum<{
710
- status: "status";
711
- recall: "recall";
712
- forget: "forget";
713
- graph_query: "graph_query";
714
- remember: "remember";
715
- update: "update";
716
- extract: "extract";
717
- }>;
718
- query: z.ZodOptional<z.ZodString>;
719
- limit: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>;
750
+ args: z.ZodDiscriminatedUnion<[z.ZodObject<{
751
+ operation: z.ZodLiteral<"recall">;
752
+ query: z.ZodString;
753
+ limit: z.ZodDefault<z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>>;
720
754
  category: z.ZodOptional<z.ZodEnum<{
721
755
  user_preference: "user_preference";
722
756
  task_context: "task_context";
@@ -734,23 +768,73 @@ declare const MemoryTool: _easbot_types.ToolDefinition & {
734
768
  other: "other";
735
769
  }>>;
736
770
  minImportance: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>;
737
- maxEdgesPerNode: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>;
738
- includeGraph: z.ZodOptional<z.ZodBoolean>;
739
- includeShared: z.ZodOptional<z.ZodBoolean>;
771
+ minScore: z.ZodOptional<z.ZodNumber>;
772
+ maxEdgesPerNode: z.ZodDefault<z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>>;
773
+ includeGraph: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
774
+ includeShared: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
775
+ }, z.core.$strict>, z.ZodObject<{
776
+ operation: z.ZodLiteral<"remember">;
777
+ content: z.ZodString;
778
+ category: z.ZodEnum<{
779
+ user_preference: "user_preference";
780
+ task_context: "task_context";
781
+ technical_fact: "technical_fact";
782
+ decision: "decision";
783
+ relationship: "relationship";
784
+ reminder: "reminder";
785
+ error_pattern: "error_pattern";
786
+ workflow: "workflow";
787
+ exploration_finding: "exploration_finding";
788
+ experience_summary: "experience_summary";
789
+ tool_usage: "tool_usage";
790
+ skill_creation: "skill_creation";
791
+ test: "test";
792
+ other: "other";
793
+ }>;
794
+ importance: z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>;
795
+ tags: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodString]>, z.ZodTransform<string[], string | string[]>>, z.ZodArray<z.ZodString>>>;
796
+ }, z.core.$strict>, z.ZodObject<{
797
+ operation: z.ZodLiteral<"update">;
798
+ factId: z.ZodString;
740
799
  content: z.ZodOptional<z.ZodString>;
800
+ category: z.ZodOptional<z.ZodEnum<{
801
+ user_preference: "user_preference";
802
+ task_context: "task_context";
803
+ technical_fact: "technical_fact";
804
+ decision: "decision";
805
+ relationship: "relationship";
806
+ reminder: "reminder";
807
+ error_pattern: "error_pattern";
808
+ workflow: "workflow";
809
+ exploration_finding: "exploration_finding";
810
+ experience_summary: "experience_summary";
811
+ tool_usage: "tool_usage";
812
+ skill_creation: "skill_creation";
813
+ test: "test";
814
+ other: "other";
815
+ }>>;
741
816
  importance: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>;
742
817
  tags: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodString]>, z.ZodTransform<string[], string | string[]>>, z.ZodArray<z.ZodString>>>;
743
- factId: z.ZodOptional<z.ZodString>;
744
- dryRun: z.ZodOptional<z.ZodBoolean>;
745
- force: z.ZodOptional<z.ZodBoolean>;
746
- lastN: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>;
818
+ }, z.core.$strict>, z.ZodObject<{
819
+ operation: z.ZodLiteral<"forget">;
820
+ factId: z.ZodString;
821
+ dryRun: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
822
+ force: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
823
+ }, z.core.$strict>, z.ZodObject<{
824
+ operation: z.ZodLiteral<"extract">;
825
+ lastN: z.ZodDefault<z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>>;
747
826
  fromMessageId: z.ZodOptional<z.ZodString>;
748
- nodeId: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>;
749
- maxDepth: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>;
750
- maxNodes: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>;
827
+ }, z.core.$strict>, z.ZodObject<{
828
+ operation: z.ZodLiteral<"graph_query">;
829
+ nodeId: z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>;
830
+ maxDepth: z.ZodDefault<z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>>;
831
+ maxNodes: z.ZodDefault<z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>>;
832
+ maxEdgesPerNode: z.ZodDefault<z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>>;
751
833
  relation: z.ZodOptional<z.ZodString>;
752
834
  type: z.ZodOptional<z.ZodString>;
753
- };
835
+ }, z.core.$strict>, z.ZodObject<{
836
+ operation: z.ZodLiteral<"status">;
837
+ }, z.core.$strict>], "operation">;
754
838
  };
755
839
 
756
840
  export { ALL_OPS, type ArchiveRecord, type ArchiveResult, COMMANDS_HELP, type CommandHelp, type ConsolidateParams, type ConsolidateResult, DEFAULT_MEMORY_JSON, type DoctorResult, type EdgeQueryFilter, type ExtractParams, type ExtractResult, type ForgetParams, type ForgetResult, type GraphQueryParams, type GraphQueryResult, GraphStore, type InitParams, type InitResult, type KGScope, LATEST_SCHEMA_VERSION, Llm, type LlmInitConfig, type LlmModels, MEMORY_CATEGORIES, MEMORY_HOOK_BINDINGS, MEMORY_HOOK_EVENTS, MEMORY_JSON_REL_PATH, MEMORY_PLUGIN_ID, MEMORY_PLUGIN_MANIFEST, MEMORY_PLUGIN_VERSION, MEMORY_TOOL_ARGS, MEMORY_TOOL_ID, MEMORY_TOOL_OPS, MIGRATIONS, MemoryCache, type MemoryCategory, type MemoryCliDeps, type MemoryCliResult, MemoryDatabaseManager, type MemoryEdge, type MemoryFact, type MemoryJson, MemoryJsonSchema, type MemoryNode, type MemoryNodeWithEdges, type MemoryOp, MemoryPlugin, MemoryPlugin as MemoryPluginEntry, MemoryPluginHook, type MemoryQuery, type MemoryRecallResult, type MemorySource, MemoryStdioServer, type MemorySystemConfig, MemoryTool, type MemoryToolOperation, type MemoryVector, type NodeQueryFilter, OP_REGISTRY, type OpAnnotations, type OpHandlerContext, type OpScope, type RecallParams, type RecallResult, type RememberParams, type RememberResult, type StatusResult, type SyncParams, type SyncResult, type UpdateParams, type UpdateResult, addWord, closeTokenizer, consolidate, createMemoryHookMatchers, doctor, executeOp, extract, forget, getGlobal, getHomeDir, getInstance, getMemoryDbPath, getMemoryDir, getXdgData, graphQuery, handleMemoryCli, init, initTokenizer, isInitialized, loadCustomDict, readCurrentSchemaVersion, recall, remember, renderBanner, renderHelp, renderOperationMarkdown, resetGlobalAdapter, resetInstanceAdapter, runMigrations, setGlobalAdapter, setInstanceAdapter, status, sync, toFtsTokens, toFtsTokensForSearch, tokenize, tokenizeForSearch, update };