@easbot/memory 0.3.27 → 0.3.29

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 (92) hide show
  1. package/README.en.md +33 -7
  2. package/README.md +27 -7
  3. package/dist/chunks/chunk-3EENVVWK.cjs +67 -0
  4. package/dist/chunks/chunk-AJDMZTCQ.mjs +1 -0
  5. package/dist/chunks/chunk-AVECFV5K.cjs +1 -0
  6. package/dist/chunks/chunk-BYNUWUL2.cjs +77 -0
  7. package/dist/chunks/chunk-CIXJXCID.mjs +1 -0
  8. package/dist/chunks/chunk-CVS25NBK.mjs +77 -0
  9. package/dist/chunks/{chunk-P45OBSAC.cjs → chunk-DVZOWMF5.cjs} +19 -19
  10. package/dist/chunks/chunk-DWGCQLSH.mjs +1 -0
  11. package/dist/chunks/chunk-GHJLFUKH.cjs +1 -0
  12. package/dist/chunks/chunk-I5SOBIRK.cjs +1 -0
  13. package/dist/chunks/{chunk-I5YSX4DQ.mjs → chunk-NWY7CUSL.mjs} +19 -19
  14. package/dist/chunks/chunk-OOBYBPIN.mjs +67 -0
  15. package/dist/chunks/chunk-QJTEXVXX.mjs +1 -0
  16. package/dist/chunks/chunk-ZDTPURG4.cjs +1 -0
  17. package/dist/chunks/cli-handler-7KD65K5T.mjs +1 -0
  18. package/dist/chunks/cli-handler-L2HSWA2P.cjs +1 -0
  19. package/dist/chunks/consolidate-ANQFG7QD.mjs +2 -0
  20. package/dist/chunks/consolidate-GJPX4H7R.cjs +2 -0
  21. package/dist/chunks/doctor-4L2KSJXV.cjs +1 -0
  22. package/dist/chunks/doctor-CDS2OUAA.mjs +1 -0
  23. package/dist/chunks/extract-3MLEFVJV.cjs +2 -0
  24. package/dist/chunks/extract-V4BIBFW7.mjs +2 -0
  25. package/dist/chunks/forget-FG7ZFJL7.cjs +3 -0
  26. package/dist/chunks/forget-PQLRSYOJ.mjs +3 -0
  27. package/dist/chunks/graph-34HVP7TP.cjs +3 -0
  28. package/dist/chunks/graph-P6LEEEVA.mjs +3 -0
  29. package/dist/chunks/init-7SHKOGVZ.cjs +1 -0
  30. package/dist/chunks/init-TTINBBT4.mjs +1 -0
  31. package/dist/chunks/{interfaces-LPJU4KS3.mjs → interfaces-7TJ645HL.mjs} +1 -1
  32. package/dist/chunks/interfaces-BGC3V4WU.cjs +1 -0
  33. package/dist/chunks/llm-RSSNHF6T.cjs +1 -0
  34. package/dist/chunks/llm-XHWMIOUN.mjs +1 -0
  35. package/dist/chunks/mcp-7TMDANN6.cjs +1 -0
  36. package/dist/chunks/mcp-YNGRYILA.mjs +1 -0
  37. package/dist/chunks/recall-JIH4PAR5.mjs +2 -0
  38. package/dist/chunks/recall-TA4YPWD2.cjs +2 -0
  39. package/dist/chunks/remember-5JAWVMYX.cjs +2 -0
  40. package/dist/chunks/remember-KY4HDAE4.mjs +2 -0
  41. package/dist/chunks/status-QZ27UQJG.mjs +1 -0
  42. package/dist/chunks/status-YGRSKKZZ.cjs +1 -0
  43. package/dist/chunks/stdio-server-KEBLOUB2.cjs +1 -0
  44. package/dist/chunks/stdio-server-RTY5WYTU.mjs +1 -0
  45. package/dist/chunks/sync-D44EAJLK.mjs +2 -0
  46. package/dist/chunks/sync-SJI7PENR.cjs +2 -0
  47. package/dist/cli.cjs +1 -1
  48. package/dist/cli.mjs +1 -1
  49. package/dist/index.cjs +5 -5
  50. package/dist/index.d.cts +35 -8
  51. package/dist/index.d.ts +35 -8
  52. package/dist/index.mjs +5 -5
  53. package/package.json +9 -9
  54. package/dist/chunks/chunk-4YADRVIU.mjs +0 -1
  55. package/dist/chunks/chunk-6CQMBEIQ.mjs +0 -1
  56. package/dist/chunks/chunk-CPRDIUQ4.cjs +0 -1
  57. package/dist/chunks/chunk-DW3CJUBO.cjs +0 -1
  58. package/dist/chunks/chunk-FY4ILCIM.mjs +0 -77
  59. package/dist/chunks/chunk-HY2LFKG7.cjs +0 -67
  60. package/dist/chunks/chunk-J5XF2W4Z.cjs +0 -1
  61. package/dist/chunks/chunk-LYBUZDJK.cjs +0 -77
  62. package/dist/chunks/chunk-WDVDYZ25.mjs +0 -1
  63. package/dist/chunks/chunk-X7P7ZFZF.mjs +0 -67
  64. package/dist/chunks/cli-handler-ETHJPZPG.mjs +0 -1
  65. package/dist/chunks/cli-handler-PG4IBTY2.cjs +0 -1
  66. package/dist/chunks/consolidate-7GFUFPLX.cjs +0 -2
  67. package/dist/chunks/consolidate-BGMXJUQX.mjs +0 -2
  68. package/dist/chunks/doctor-C2FWFUDO.mjs +0 -1
  69. package/dist/chunks/doctor-SCXUJRSG.cjs +0 -1
  70. package/dist/chunks/extract-O4IOL6BZ.cjs +0 -2
  71. package/dist/chunks/extract-RBBSVK2S.mjs +0 -2
  72. package/dist/chunks/forget-JTACRG7Y.mjs +0 -3
  73. package/dist/chunks/forget-M4I6GVWI.cjs +0 -3
  74. package/dist/chunks/graph-AOMDJ6YA.cjs +0 -3
  75. package/dist/chunks/graph-VBVVRV6V.mjs +0 -3
  76. package/dist/chunks/init-2SBK7ZWO.mjs +0 -1
  77. package/dist/chunks/init-VTPJR56L.cjs +0 -1
  78. package/dist/chunks/interfaces-Q5OGU5EK.cjs +0 -1
  79. package/dist/chunks/llm-7LQGYSUE.cjs +0 -1
  80. package/dist/chunks/llm-UHTBU2HA.mjs +0 -1
  81. package/dist/chunks/mcp-VIOHPDO5.cjs +0 -1
  82. package/dist/chunks/mcp-ZQCLVZIR.mjs +0 -1
  83. package/dist/chunks/recall-JSTQDGGZ.cjs +0 -2
  84. package/dist/chunks/recall-UQSG6ECA.mjs +0 -2
  85. package/dist/chunks/remember-GVQJ5G7Z.mjs +0 -2
  86. package/dist/chunks/remember-Z4UJJN62.cjs +0 -2
  87. package/dist/chunks/status-DH33MQZV.cjs +0 -1
  88. package/dist/chunks/status-VZ5EBAOY.mjs +0 -1
  89. package/dist/chunks/stdio-server-JC53PUET.mjs +0 -1
  90. package/dist/chunks/stdio-server-OUZAN4IM.cjs +0 -1
  91. package/dist/chunks/sync-6I2ZJUH6.cjs +0 -2
  92. package/dist/chunks/sync-UT4D32ML.mjs +0 -2
@@ -1,24 +1,24 @@
1
- 'use strict';var chunkHY2LFKG7_cjs=require('./chunk-HY2LFKG7.cjs'),mcp=require('@easbot/mcp'),utils=require('@easbot/utils');var oe=utils.Log.create({service:"memory-format-truncate"}),J="**`";var X=24e3,Z=25e3;async function $(e,n={}){let o=n.softLimit??X,s=n.hardCeiling??Z,r=n.toolName??"memory",c=n.writeToDisk!==false;if(e.length<=o)return {content:e,truncated:false};let d=e.slice(0,s),t=d.lastIndexOf(`
2
- ${J}`),a=d.lastIndexOf(`
3
- `),m;t>s*.5?m=t:a>0?m=a:m=-1;let u=m>0?d.slice(0,m):d,i=u+"\n\n... (output truncated to budget; the source above is complete and verbatim \u2014 treat it as already Read. For any area not covered, make ANOTHER `<tool>` targeting those names \u2014 do NOT Read these files.)";if(!c)return {content:i,truncated:true,outputPath:"",hint:"Make another recall / graph_query with narrower scope.",info:`... ${e.length-u.length}/${e.length} characters truncated ...`};try{let p=await utils.TruncateContent.truncate(e,{maxChars:u.length,direction:"head",label:`${r}-output`});return p.truncated?{content:i,truncated:!0,outputPath:p.outputPath,hint:utils.TruncateContent.formatHint(p),info:`... ${p.removedLength}/${p.originalLength} characters truncated ...`}:{content:i,truncated:!0,outputPath:"",hint:"Make another recall / graph_query with narrower scope.",info:`... ${e.length-u.length}/${e.length} characters truncated ...`}}catch(p){return oe.warn("TruncateContent.truncate failed, returning without disk hint",{error:p instanceof Error?p.message:String(p)}),{content:i,truncated:true,outputPath:"",hint:"Make another recall / graph_query with narrower scope.",info:`... ${e.length-u.length}/${e.length} characters truncated ...`}}}function w(e,n={}){let o=n.softLimit??X,s=n.hardCeiling??Z;if(e.length<=o)return {content:e,truncated:false};let r=e.slice(0,s),c=r.lastIndexOf(`
4
- ${J}`),d=r.lastIndexOf(`
1
+ 'use strict';var chunk3EENVVWK_cjs=require('./chunk-3EENVVWK.cjs'),chunkAVECFV5K_cjs=require('./chunk-AVECFV5K.cjs'),mcp=require('@easbot/mcp'),utils=require('@easbot/utils');var ie=utils.Log.create({service:"memory-format-truncate"}),X="**`";var Z=24e3,ee=25e3;async function $(e,n={}){let o=n.softLimit??Z,s=n.hardCeiling??ee,r=n.toolName??"memory",c=n.writeToDisk!==false;if(e.length<=o)return {content:e,truncated:false};let d=e.slice(0,s),t=d.lastIndexOf(`
2
+ ${X}`),a=d.lastIndexOf(`
3
+ `),m;t>s*.5?m=t:a>0?m=a:m=-1;let u=m>0?d.slice(0,m):d,i=u+"\n\n... (output truncated to budget; the source above is complete and verbatim \u2014 treat it as already Read. For any area not covered, make ANOTHER `<tool>` targeting those names \u2014 do NOT Read these files.)";if(!c)return {content:i,truncated:true,outputPath:"",hint:"Make another recall / graph_query with narrower scope.",info:`... ${e.length-u.length}/${e.length} characters truncated ...`};try{let f=await utils.TruncateContent.truncate(e,{maxChars:u.length,direction:"head",label:`${r}-output`});return f.truncated?{content:i,truncated:!0,outputPath:f.outputPath,hint:utils.TruncateContent.formatHint(f),info:`... ${f.removedLength}/${f.originalLength} characters truncated ...`}:{content:i,truncated:!0,outputPath:"",hint:"Make another recall / graph_query with narrower scope.",info:`... ${e.length-u.length}/${e.length} characters truncated ...`}}catch(f){return ie.warn("TruncateContent.truncate failed, returning without disk hint",{error:utils.errorMeta(f)}),{content:i,truncated:true,outputPath:"",hint:"Make another recall / graph_query with narrower scope.",info:`... ${e.length-u.length}/${e.length} characters truncated ...`}}}function w(e,n={}){let o=n.softLimit??Z,s=n.hardCeiling??ee;if(e.length<=o)return {content:e,truncated:false};let r=e.slice(0,s),c=r.lastIndexOf(`
4
+ ${X}`),d=r.lastIndexOf(`
5
5
  `),t;c>s*.5?t=c:d>0?t=d:t=-1;let a=t>0?r.slice(0,t):r;return {content:a+`
6
6
 
7
- ... (output truncated; tail dropped at section boundary)`,truncated:true,outputPath:"",hint:"",info:`... ${e.length-a.length}/${e.length} characters truncated ...`}}function ae(e,n){if(!e||e.length===0)return null;let o=e.filter(r=>n.has(r.path));return o.length===0?null:`\u26A0\uFE0F Index may be stale for: ${o.map(r=>`${r.path} (edited pending)`).join(", ")}
7
+ ... (output truncated; tail dropped at section boundary)`,truncated:true,outputPath:"",hint:"",info:`... ${e.length-a.length}/${e.length} characters truncated ...`}}function de(e,n){if(!e||e.length===0)return null;let o=e.filter(r=>n.has(r.path));return o.length===0?null:`\u26A0\uFE0F Index may be stale for: ${o.map(r=>`${r.path} (edited pending)`).join(", ")}
8
8
 
9
- `}function I(e,n,o={}){return (ee[e]??ee.default).replace(/<(\w+)>/g,(r,c)=>c==="tool"?n:o[c]??`<${c}>`)}var ee={recall:"If you need more facts, make ANOTHER `<tool>` query with a different scope / interval.\nIf you have enough context, proceed with the current task. Do NOT call `<tool>` again for the same query.",remember:"Memory persisted. To recall it later, use `<tool>` with the same query.\nDo NOT call `<tool>` again to verify \u2014 the fact is already in the database.",forget:"Memory deleted. To verify, run `<tool>` with the same filter (no results expected).\nIf you deleted too much, the data is gone (no auto-restore).",graph_query:"If you need to explore further, make ANOTHER `<tool>` from a different start node or depth.\nOtherwise, the graph is complete for this scope.",status:"Status snapshot. To inspect a specific fact, use `<tool>` (recall) with its id.\nOtherwise, this is a complete read.",consolidate:"Consolidation done. To inspect the new facts, use `<tool>` with the same agentId.\nIf you want to undo, archives are in <archive_dir>.",doctor:"Doctor report. To fix a failing check, run with `repair=true`.\nRe-run after fix to confirm.",default:"If you need more, make ANOTHER `<tool>` with refined parameters.\nOtherwise, this is a complete read."};function se(e){let n=Array.isArray(e.edges)?e.edges.length:0;return ` - node #${e.id}: ${e.name} (${e.type}) [edges: ${n}]`}function te(e,n,o,s){let r=e.tags&&e.tags.length>0?`
9
+ `}function I(e,n,o={}){return (te[e]??te.default).replace(/<(\w+)>/g,(r,c)=>c==="tool"?n:o[c]??`<${c}>`)}var te={recall:"If you need more facts, make ANOTHER `<tool>` query with a different scope / interval.\nIf you have enough context, proceed with the current task. Do NOT call `<tool>` again for the same query.",remember:"Memory persisted. To recall it later, use `<tool>` with the same query.\nDo NOT call `<tool>` again to verify \u2014 the fact is already in the database.",forget:"Memory deleted. To verify, run `<tool>` with the same filter (no results expected).\nIf you deleted too much, the data is gone (no auto-restore).",graph_query:"If you need to explore further, make ANOTHER `<tool>` from a different start node or depth.\nOtherwise, the graph is complete for this scope.",status:"Status snapshot. To inspect a specific fact, use `<tool>` (recall) with its id.\nOtherwise, this is a complete read.",consolidate:"Consolidation done. To inspect the new facts, use `<tool>` with the same agentId.\nIf you want to undo, archives are in <archive_dir>.",doctor:"Doctor report. To fix a failing check, run with `repair=true`.\nRe-run after fix to confirm.",default:"If you need more, make ANOTHER `<tool>` with refined parameters.\nOtherwise, this is a complete read."};function ce(e){let n=Array.isArray(e.edges)?e.edges.length:0;return ` - node #${e.id}: ${e.name} (${e.type}) [edges: ${n}]`}function ne(e,n,o,s){let r=e.tags&&e.tags.length>0?`
10
10
  - tags: ${e.tags.join(", ")}`:"",c=e.sessionId?`
11
11
  - session: ${e.sessionId}`:"",d=e.msgId?`
12
12
  - msg: ${e.msgId}`:"",t=typeof n=="number"?`
13
- - score: ${n.toFixed(3)}${o?` (${o})`:""}`:"",a=e.truncated?" [truncated]":"",m="";if(s&&s.length>0){let u=s.map(se);m=`
13
+ - score: ${n.toFixed(3)}${o?` (${o})`:""}`:"",a=e.truncated?" [truncated]":"",m="";if(s&&s.length>0){let u=s.map(ce);m=`
14
14
  - linked KG nodes (${s.length}) \u2014 use \`graph_query(nodeId=<id>)\` for full relation graph:
15
15
  ${u.join(`
16
16
  `)}`;}return [`### \`${e.id}\`${a}`,` - agentId: ${e.agentId}`,` - category: ${e.category}`,` - importance: ${e.importance}`,` - createdAt: ${e.createdAt}`,` - updatedAt: ${e.updatedAt}`,` - source: ${e.source}${t}${r}${c}${d}${m}`,"",e.content,""].join(`
17
- `)}async function k(e,n){let o=n.toolName??"memory_recall",s=`**\`memory_recall:${n.query.slice(0,40).replace(/[^a-zA-Z0-9_]/g,"_")}\`**`,r=ae(n.pendingFiles,new Set),d=[`Found ${e.total} fact(s) for query "${n.query}" (agentId=${n.agentId}, scope=${n.scope}):`,"",r??"",s].join(`
18
- `),t=new Map;for(let l of e.hits){let i=l.fact.category;t.has(i)||t.set(i,[]),t.get(i).push(l);}let a=Array.from(t.entries()).map(([l,i])=>{let p=`**\`category:${l}\`**`,h=i.map(f=>te(f.fact,f.score,f.source,f.nodes)).join(`
19
- `);return `${p}
17
+ `)}async function v(e,n){let o=n.toolName??"memory_recall",s=`**\`memory_recall:${n.query.slice(0,40).replace(/[^a-zA-Z0-9_]/g,"_")}\`**`,r=de(n.pendingFiles,new Set),d=[`Found ${e.total} fact(s) for query "${n.query}" (agentId=${n.agentId}, scope=${n.scope}):`,"",r??"",s].join(`
18
+ `),t=new Map;for(let l of e.hits){let i=l.fact.category;t.has(i)||t.set(i,[]),t.get(i).push(l);}let a=Array.from(t.entries()).map(([l,i])=>{let f=`**\`category:${l}\`**`,p=i.map(g=>ne(g.fact,g.score,g.source,g.nodes)).join(`
19
+ `);return `${f}
20
20
 
21
- ${h}`}).join(`
21
+ ${p}`}).join(`
22
22
  `),m=e.warnings&&e.warnings.length>0?`
23
23
 
24
24
  \u26A0\uFE0F warnings:
@@ -28,7 +28,7 @@ ${e.warnings.map(l=>` - ${l}`).join(`
28
28
 
29
29
  ${a}${m}
30
30
 
31
- ${I("recall",o)}`;return n.sync?w(u,{}).content:(await $(u,{toolName:o,writeToDisk:n.writeToDisk})).content}async function v(e,n={}){let o=n.toolName??"memory_remember",s=`**\`memory_remember:${e.fact.id}\`**`,r=te(e.fact),c=e.nodeIds??[],d=c.length>0?`
31
+ ${I("recall",o)}`;return n.sync?w(u,{}).content:(await $(u,{toolName:o,writeToDisk:n.writeToDisk})).content}async function M(e,n={}){let o=n.toolName??"memory_remember",s=`**\`memory_remember:${e.fact.id}\`**`,r=ne(e.fact),c=e.nodeIds??[],d=c.length>0?`
32
32
  - linked KG nodes: ${c.join(", ")}
33
33
  `:"",t=`${s}
34
34
 
@@ -41,24 +41,24 @@ ${e.deletedIds.map(t=>` - ${t}`).join(`
41
41
  `),c=e.edges.map(t=>` - edge #${t.id}: ${t.source} --${t.relation}--> ${t.target}`).join(`
42
42
  `),d=[s,"",`nodes (${e.nodes.length}${e.truncated?` / total ${e.totalNodes}`:""}):`,r||" (none)","",`edges (${e.edges.length}${e.truncated?` / total ${e.totalEdges}`:""}):`,c||" (none)","",I("graph_query",o)].join(`
43
43
  `);return n.sync?w(d,{}).content:(await $(d,{toolName:o,writeToDisk:n.writeToDisk})).content}async function N(e,n={}){let o=n.toolName??"memory_status",r=["**`memory_status`**","",`dbPath: ${e.dbPath}`,`workspaceDir: ${e.workspaceDir}`,`factsCount: ${e.factsCount}`,`nodesCount: ${e.nodesCount} (KG nodes)`,`edgesCount: ${e.edgesCount} (KG edges)`,`ftsAvailable: ${e.ftsAvailable?"yes":"no"}`,`vectorEnabled: ${e.vectorEnabled?"yes":"no"}`,`healthy: ${e.healthy?"yes":"no"}`,"","factsByCategory:",...Object.entries(e.factsByCategory).map(([d,t])=>` - ${d}: ${t}`),"","meta:",...Object.entries(e.meta).map(([d,t])=>` - ${d}: ${t}`)];if(e.integrityStats&&Object.keys(e.integrityStats).length>0){r.push("","DB stats:");let d=Math.max(...Object.keys(e.integrityStats).map(t=>t.length));for(let[t,a]of Object.entries(e.integrityStats))r.push(` - ${t.padEnd(d)} ${a}`);}r.push("",I("status",o));let c=r.join(`
44
- `);return n.sync?w(c,{}).content:(await $(c,{toolName:o,writeToDisk:n.writeToDisk})).content}async function M(e,n={}){let o=n.toolName??"memory_consolidate",r=["**`memory_consolidate:result`**","",`total facts scanned: ${e.totalFacts}`,`deduped (merged): ${e.dedupedCount}`,`compressed: ${e.compressedCount}`,`archived to archive/: ${e.archivedCount}`,`skipped (no change): ${e.skippedCount}`,`duration: ${e.durationMs}ms`,"",I("consolidate",o)].join(`
45
- `);return n.sync?w(r,{}).content:(await $(r,{toolName:o,writeToDisk:n.writeToDisk})).content}var S=20;async function O(e,n={}){let o=n.toolName??"memory_sync",r=[`**\`memory_sync:${e.dryRun?"DRY_RUN":"OK"}\`**`,"",`windowDays: ${e.windowDays} (threshold: ${e.archiveThreshold})`,"","## Stage A (db \u2192 .md)",`- generated: ${e.generatedCount}`,`- skipped (idempotent): ${e.skippedCount}`,`- failed (best-effort): ${e.failedGenerateCount}`,"","## Stage B (active/ \u2192 archive/)",`- ${e.dryRun?"would archive":"archived"}: ${e.archivedCount}`];if(e.archivedRecords.length>0){r.push("","### Archived records:");let d=e.archivedRecords.slice(0,S);for(let t of d)r.push(`- ${t.firstFactId} (${t.firstCreatedAt})`),r.push(` - source: \`${t.source}\``),r.push(` - target: \`${t.target}\``);e.archivedRecords.length>S&&r.push(`... and ${e.archivedRecords.length-S} more (use --json for full list)`);}r.push("",`duration: ${e.durationMs}ms`,"",I("sync",o));let c=r.join(`
46
- `);return n.sync?w(c,{}).content:(await $(c,{toolName:o,writeToDisk:n.writeToDisk})).content}async function P(e,n={}){let o=n.toolName??"memory_doctor",s=`**\`memory_doctor:${e.healthy?"OK":"ISSUES"}\`**`,r=t=>t?"\u2705":"\u274C",c=e.checks.map(t=>`${r(t.passed)} ${t.name}: ${t.message}`).join(`
44
+ `);return n.sync?w(c,{}).content:(await $(c,{toolName:o,writeToDisk:n.writeToDisk})).content}async function O(e,n={}){let o=n.toolName??"memory_consolidate",r=["**`memory_consolidate:result`**","",`total facts scanned: ${e.totalFacts}`,`deduped (merged): ${e.dedupedCount}`,`compressed: ${e.compressedCount}`,`archived to archive/: ${e.archivedCount}`,`skipped (no change): ${e.skippedCount}`,`duration: ${e.durationMs}ms`,"",I("consolidate",o)].join(`
45
+ `);return n.sync?w(r,{}).content:(await $(r,{toolName:o,writeToDisk:n.writeToDisk})).content}var S=20;async function P(e,n={}){let o=n.toolName??"memory_sync",r=[`**\`memory_sync:${e.dryRun?"DRY_RUN":"OK"}\`**`,"",`windowDays: ${e.windowDays} (threshold: ${e.archiveThreshold})`,"","## Stage A (db \u2192 .md)",`- generated: ${e.generatedCount}`,`- skipped (idempotent): ${e.skippedCount}`,`- failed (best-effort): ${e.failedGenerateCount}`,"","## Stage B (active/ \u2192 archive/)",`- ${e.dryRun?"would archive":"archived"}: ${e.archivedCount}`];if(e.archivedRecords.length>0){r.push("","### Archived records:");let d=e.archivedRecords.slice(0,S);for(let t of d)r.push(`- ${t.firstFactId} (${t.firstCreatedAt})`),r.push(` - source: \`${t.source}\``),r.push(` - target: \`${t.target}\``);e.archivedRecords.length>S&&r.push(`... and ${e.archivedRecords.length-S} more (use --json for full list)`);}r.push("",`duration: ${e.durationMs}ms`,"",I("sync",o));let c=r.join(`
46
+ `);return n.sync?w(c,{}).content:(await $(c,{toolName:o,writeToDisk:n.writeToDisk})).content}async function j(e,n={}){let o=n.toolName??"memory_doctor",s=`**\`memory_doctor:${e.healthy?"OK":"ISSUES"}\`**`,r=t=>t?"\u2705":"\u274C",c=e.checks.map(t=>`${r(t.passed)} ${t.name}: ${t.message}`).join(`
47
47
  `),d=[s,"",c,"",I("doctor",o)].join(`
48
- `);return n.sync?w(d,{}).content:(await $(d,{toolName:o,writeToDisk:n.writeToDisk})).content}async function R(e,n,o={}){let s=n,r=typeof s.kind=="string";switch((r?s:{kind:e}).kind){case "recall":{let d=r?{hits:s.hits,total:s.totalCount??s.total??0,truncated:s.truncated??false}:n;return k(d,{...o,query:s.query??o.query??"",agentId:s.agentId??o.agentId??"",scope:s.scope??o.scope??"agent_only"})}case "remember":{let d=r?{fact:s.fact,nodeIds:s.nodeIds}:n;return v(d,o)}case "forget":return A(r?s:n,o);case "graph_query":return _(r?s:n,o);case "status":return N(r?s:n,o);case "consolidate":return M(r?s:n,o);case "sync":return O(r?s:n,o);case "doctor":return P(r?s:n,o);default:throw new Error(`renderOperationMarkdown: unsupported op "${e}"`)}}var x=utils.Log.create({service:"memory-mcp-stdio"});function Ie(e){let n=new Map,o=e.isRemote??true,s=!o;function r(t){let a=utils.Locale.resolveLocaleLang();return {agentId:t.agentId??e.agentId,isTrustedLocal:t.isTrustedLocal??s,remote:o,locale:a,dbPath:e.dbPath,workspaceDir:e.workspaceDir,rootDir:e.workspaceDir,config:chunkHY2LFKG7_cjs.A({agentId:e.agentId,dbPath:e.dbPath})}}function c(t,a){return {content:[{type:"text",text:t}],isError:a}}function d(t){return mcp.formatFailClosed(t,s)}return n.set("recall",async t=>{try{let a=t,m=r({agentId:a.agentId}),u=await chunkHY2LFKG7_cjs.z("recall",t,m);return {content:[{type:"text",text:await R("recall",u,{toolName:"memory_recall",query:a.query,agentId:a.agentId??e.agentId,scope:a.scope??"agent_only"})}]}}catch(a){return c(d(a),true)}}),n.set("remember",async t=>{try{let m=r({agentId:t.agentId}),u=await chunkHY2LFKG7_cjs.z("remember",t,m);return {content:[{type:"text",text:await R("remember",u,{toolName:"memory_remember"})}]}}catch(a){return c(d(a),true)}}),n.set("update",async t=>{try{let m=r({agentId:t.agentId}),u=await chunkHY2LFKG7_cjs.z("update",t,m),l=u.fieldsUpdated.length>0?u.fieldsUpdated.join(", "):"(no-op)",i=u.contentChanged?" (embedding rewritten)":"";return {content:[{type:"text",text:`Memory updated.
48
+ `);return n.sync?w(d,{}).content:(await $(d,{toolName:o,writeToDisk:n.writeToDisk})).content}async function R(e,n,o={}){let s=n,r=typeof s.kind=="string";switch((r?s:{kind:e}).kind){case "recall":{let d=r?{hits:s.hits,total:s.totalCount??s.total??0,truncated:s.truncated??false}:n;return v(d,{...o,query:s.query??o.query??"",agentId:s.agentId??o.agentId??"",scope:s.scope??o.scope??"agent_only"})}case "remember":{let d=r?{fact:s.fact,nodeIds:s.nodeIds}:n;return M(d,o)}case "forget":return A(r?s:n,o);case "graph_query":return _(r?s:n,o);case "status":return N(r?s:n,o);case "consolidate":return O(r?s:n,o);case "sync":return P(r?s:n,o);case "doctor":return j(r?s:n,o);default:throw new chunkAVECFV5K_cjs.a.UnsupportedOperationError({message:`renderOperationMarkdown: unsupported op "${e}"`,opName:e,renderer:"markdown"})}}var D=utils.Log.create({service:"memory-mcp-stdio"});function Te(e){let n=new Map,o=e.isRemote??true,s=!o;function r(t){let a=utils.Locale.resolveLocaleLang();return {agentId:t.agentId??e.agentId,isTrustedLocal:t.isTrustedLocal??s,remote:o,locale:a,dbPath:e.dbPath,workspaceDir:e.workspaceDir,rootDir:e.workspaceDir,config:chunk3EENVVWK_cjs.A({agentId:e.agentId,dbPath:e.dbPath})}}function c(t,a){return {content:[{type:"text",text:t}],isError:a}}function d(t){return mcp.formatFailClosed(t,s)}return n.set("recall",async t=>{try{let a=t,m=r({agentId:a.agentId}),u=await chunk3EENVVWK_cjs.z("recall",t,m);return {content:[{type:"text",text:await R("recall",u,{toolName:"memory_recall",query:a.query,agentId:a.agentId??e.agentId,scope:a.scope??"agent_only"})}]}}catch(a){return c(d(a),true)}}),n.set("remember",async t=>{try{let m=r({agentId:t.agentId}),u=await chunk3EENVVWK_cjs.z("remember",t,m);return {content:[{type:"text",text:await R("remember",u,{toolName:"memory_remember"})}]}}catch(a){return c(d(a),true)}}),n.set("update",async t=>{try{let m=r({agentId:t.agentId}),u=await chunk3EENVVWK_cjs.z("update",t,m),l=u.fieldsUpdated.length>0?u.fieldsUpdated.join(", "):"(no-op)",i=u.contentChanged?" (embedding rewritten)":"";return {content:[{type:"text",text:`Memory updated.
49
49
  id: ${u.fact.id}
50
50
  category: ${u.fact.category}
51
51
  importance: ${u.fact.importance}
52
52
  fields updated: ${l}${i}
53
53
  updated_at: ${u.fact.updatedAt}
54
- `}]}}catch(a){return c(d(a),true)}}),n.set("forget",async t=>{try{let m=r({agentId:t.agentId}),u=await chunkHY2LFKG7_cjs.z("forget",t,m);return {content:[{type:"text",text:await R("forget",u,{toolName:"memory_forget"})}]}}catch(a){return c(d(a),true)}}),n.set("extract",async t=>{try{let m=r({agentId:t.agentId}),l=await chunkHY2LFKG7_cjs.z("extract",t,m);return {content:[{type:"text",text:`Extract completed.
54
+ `}]}}catch(a){return c(d(a),true)}}),n.set("forget",async t=>{try{let m=r({agentId:t.agentId}),u=await chunk3EENVVWK_cjs.z("forget",t,m);return {content:[{type:"text",text:await R("forget",u,{toolName:"memory_forget"})}]}}catch(a){return c(d(a),true)}}),n.set("extract",async t=>{try{let m=r({agentId:t.agentId}),l=await chunk3EENVVWK_cjs.z("extract",t,m);return {content:[{type:"text",text:`Extract completed.
55
55
  sessionId: ${t.sessionId??"(unknown)"}
56
56
  extractedCount: ${l.extractedCount}
57
57
  factIds: ${l.factIds.length>0?l.factIds.join(", "):"(none)"}
58
58
  messageRange: ${l.messageRange.fromMessageId} -> ${l.messageRange.toMessageId}
59
- `}]}}catch(a){return c(d(a),true)}}),n.set("consolidate",async t=>{try{let m=r({agentId:t.agentId,isTrustedLocal:!0}),u=await chunkHY2LFKG7_cjs.z("consolidate",t,m);return {content:[{type:"text",text:await R("consolidate",u,{toolName:"memory_consolidate"})}]}}catch(a){return c(d(a),true)}}),n.set("sync",async t=>{try{let m=t.agentId?.trim();if(!m)return c(d(new Error("memory_sync: agentId is required (sync requires agentId, see ADR 0069)")),!0);let u=r({agentId:m,isTrustedLocal:!0}),l=await chunkHY2LFKG7_cjs.z("sync",t,u);return {content:[{type:"text",text:await R("sync",l,{toolName:"memory_sync"})}]}}catch(a){return c(d(a),true)}}),n.set("graph_query",async t=>{try{let a=t,m=r({agentId:a.agentId}),u=await chunkHY2LFKG7_cjs.z("graph_query",t,m);return {content:[{type:"text",text:await R("graph_query",u,{toolName:"memory_graph_query",scope:a.scope??"agent_only"})}]}}catch(a){return c(d(a),true)}}),n.set("status",async t=>{try{let m=r({agentId:(t??{}).agentId}),u=await chunkHY2LFKG7_cjs.z("status",t,m),{renderKnowledgeStatus:l}=await import('@easbot/terminal'),i=u;return {content:[{type:"text",text:l({packageName:"memory",rootDir:i.workspaceDir??"",configPath:i.configPath??"",configExists:typeof i.configExists=="boolean"?i.configExists:!0,dbPath:i.dbPath??"",dbExists:typeof i.dbExists=="boolean"?i.dbExists:!0,dbSize:typeof i.dbSize=="number"?i.dbSize:void 0,indexState:i.indexState,schemaVersion:typeof i.schemaVersion=="number"?i.schemaVersion:void 0,extractionVersion:typeof i.extractionVersion=="number"?i.extractionVersion:void 0,lastSyncAt:i.lastSyncAt,vectorEnabled:typeof i.vectorEnabled=="boolean"?i.vectorEnabled:!1,embeddingDims:typeof i.embeddingDims=="number"?i.embeddingDims:void 0,llm:i.llm??{initialized:!1,capabilities:{}},backend:i.backend,healthy:typeof i.healthy=="boolean"?i.healthy:!0,recommendation:i.recommendation,dbStats:(()=>{let h=i.dbStats;if(h&&typeof h=="object"&&Object.keys(h).length>0)return {...h};let f=i.integrityStats;if(f&&typeof f=="object"&&Object.keys(f).length>0)return {...f}})(),extras:(()=>{let h={};if(typeof i.agentId=="string"&&(h.agent_id=i.agentId),typeof i.ftsAvailable=="boolean"&&(h.fts_available=i.ftsAvailable?"yes":"no"),i.factsByCategory&&typeof i.factsByCategory=="object")for(let[f,b]of Object.entries(i.factsByCategory))typeof b=="number"&&b>0&&(h[`facts/${f}`]=b);if(i.meta&&typeof i.meta=="object")for(let[f,b]of Object.entries(i.meta))b!==void 0&&(h[`meta/${f}`]=b);return Object.keys(h).length>0?h:void 0})()})}]}}catch(a){return c(d(a),true)}}),n.set("doctor",async t=>{try{let m=r({agentId:(t??{}).agentId,isTrustedLocal:!0}),u=await chunkHY2LFKG7_cjs.z("doctor",t,m);return {content:[{type:"text",text:await R("doctor",u,{toolName:"memory_doctor"})}]}}catch(a){return c(d(a),true)}}),n.set("init",async t=>{try{let a=r({isTrustedLocal:!0}),u=await chunkHY2LFKG7_cjs.z("init",t,a);return {content:[{type:"text",text:`Init complete.
59
+ `}]}}catch(a){return c(d(a),true)}}),n.set("consolidate",async t=>{try{let m=r({agentId:t.agentId,isTrustedLocal:!0}),u=await chunk3EENVVWK_cjs.z("consolidate",t,m);return {content:[{type:"text",text:await R("consolidate",u,{toolName:"memory_consolidate"})}]}}catch(a){return c(d(a),true)}}),n.set("sync",async t=>{try{let m=t.agentId?.trim();if(!m)return c(d(new Error("memory_sync: agentId is required (sync requires agentId, see ADR 0069)")),!0);let u=r({agentId:m,isTrustedLocal:!0}),l=await chunk3EENVVWK_cjs.z("sync",t,u);return {content:[{type:"text",text:await R("sync",l,{toolName:"memory_sync"})}]}}catch(a){return c(d(a),true)}}),n.set("graph_query",async t=>{try{let a=t,m=r({agentId:a.agentId}),u=await chunk3EENVVWK_cjs.z("graph_query",t,m);return {content:[{type:"text",text:await R("graph_query",u,{toolName:"memory_graph_query",scope:a.scope??"agent_only"})}]}}catch(a){return c(d(a),true)}}),n.set("status",async t=>{try{let m=r({agentId:(t??{}).agentId}),u=await chunk3EENVVWK_cjs.z("status",t,m),{renderKnowledgeStatus:l}=await import('@easbot/terminal'),i=u;return {content:[{type:"text",text:l({packageName:"memory",rootDir:i.workspaceDir??"",configPath:i.configPath??"",configExists:typeof i.configExists=="boolean"?i.configExists:!0,dbPath:i.dbPath??"",dbExists:typeof i.dbExists=="boolean"?i.dbExists:!0,dbSize:typeof i.dbSize=="number"?i.dbSize:void 0,indexState:i.indexState,schemaVersion:typeof i.schemaVersion=="number"?i.schemaVersion:void 0,extractionVersion:typeof i.extractionVersion=="number"?i.extractionVersion:void 0,lastSyncAt:i.lastSyncAt,vectorEnabled:typeof i.vectorEnabled=="boolean"?i.vectorEnabled:!1,embeddingDims:typeof i.embeddingDims=="number"?i.embeddingDims:void 0,llm:i.llm??{initialized:!1,capabilities:{}},backend:i.backend,healthy:typeof i.healthy=="boolean"?i.healthy:!0,recommendation:i.recommendation,dbStats:(()=>{let p=i.dbStats;if(p&&typeof p=="object"&&Object.keys(p).length>0)return {...p};let g=i.integrityStats;if(g&&typeof g=="object"&&Object.keys(g).length>0)return {...g}})(),extras:(()=>{let p={};if(typeof i.agentId=="string"&&(p.agent_id=i.agentId),typeof i.ftsAvailable=="boolean"&&(p.fts_available=i.ftsAvailable?"yes":"no"),i.factsByCategory&&typeof i.factsByCategory=="object")for(let[g,b]of Object.entries(i.factsByCategory))typeof b=="number"&&b>0&&(p[`facts/${g}`]=b);if(i.meta&&typeof i.meta=="object")for(let[g,b]of Object.entries(i.meta))b!==void 0&&(p[`meta/${g}`]=b);return Object.keys(p).length>0?p:void 0})()})}]}}catch(a){return c(d(a),true)}}),n.set("doctor",async t=>{try{let m=r({agentId:(t??{}).agentId,isTrustedLocal:!0}),u=await chunk3EENVVWK_cjs.z("doctor",t,m);return {content:[{type:"text",text:await R("doctor",u,{toolName:"memory_doctor"})}]}}catch(a){return c(d(a),true)}}),n.set("init",async t=>{try{let a=r({isTrustedLocal:!0}),u=await chunk3EENVVWK_cjs.z("init",t,a);return {content:[{type:"text",text:`Init complete.
60
60
  dbPath: ${u.dbPath}
61
61
  tablesCreated: ${u.tablesCreated}
62
62
  migrationsApplied: ${u.migrationsApplied}
63
63
  durationMs: ${u.durationMs}
64
- `}]}}catch(a){return c(d(a),true)}}),n}var Re={recall:chunkHY2LFKG7_cjs.c,remember:chunkHY2LFKG7_cjs.d,update:chunkHY2LFKG7_cjs.e,forget:chunkHY2LFKG7_cjs.f,extract:chunkHY2LFKG7_cjs.g,consolidate:chunkHY2LFKG7_cjs.h,sync:chunkHY2LFKG7_cjs.m,graph_query:chunkHY2LFKG7_cjs.i,status:chunkHY2LFKG7_cjs.j,doctor:chunkHY2LFKG7_cjs.k,init:chunkHY2LFKG7_cjs.l};function Ce(e,n){let o=chunkHY2LFKG7_cjs.x[e],s={title:o?.annotations?.defaultDescription??e,readOnlyHint:o?.annotations?.readOnlyHint??false,destructiveHint:o?.annotations?.destructiveHint??false,idempotentHint:o?.annotations?.idempotentHint??true,openWorldHint:false},r=Re[e];return {name:e,description:o?.annotations?.defaultDescription??`memory op: ${e}`,inputSchema:r??{type:"object",properties:{},required:[],additionalProperties:false},annotations:s,handler:n}}exports.b=void 0;(o=>{async function e(s,r){let{getMemoryDbPath:c,getInstance:d}=await import('./interfaces-Q5OGU5EK.cjs'),a=r!==null&&typeof r=="object"&&"agentId"in r&&"dbPath"in r?r:{agentId:process.env.EASBOT_AGENT_ID??"default",dbPath:c(),workspaceDir:d().worktree,isRemote:false};mcp.extendKnownErrorCodes(["AGENT_ID_REQUIRED","SESSION_ID_REQUIRED","CATEGORY_REQUIRED","IMPORTANCE_REQUIRED","TIMERANGE_REQUIRED","DRY_RUN_NO_DELETE"]);let m=new mcp.ToolRegistry,u=Ie(a),l=Object.keys(chunkHY2LFKG7_cjs.x);for(let g of l){let C=u.get(g);if(!C)throw new Error(`MemoryStdioServer.start: missing handler for tool "${g}"`);m.register(Ce(g,C));}x.info("starting memory MCP stdio server",{id:s.id,name:s.name,toolCount:l.length,isRemote:a.isRemote??true});let i=await mcp.createAndStartStdioServer(s,m),p=null,h=new Promise(g=>{p=g;}),f=g=>{x.info("received signal, stopping MCP server",{signal:g}),p?.();},b=()=>f("SIGINT"),D=()=>f("SIGTERM"),j=(g,C)=>process.listeners(g).includes(C);j("SIGINT",b)||process.on("SIGINT",b),j("SIGTERM",D)||process.on("SIGTERM",D);try{await h;}finally{try{process.off("SIGINT",b),process.off("SIGTERM",D);}catch(g){x.warn("failed to remove signal handlers",{error:g instanceof Error?g.message:String(g)});}try{await i.stop();}catch(g){x.warn("server.stop failed during cleanup",{error:g instanceof Error?g.message:String(g)});}}return {id:s.id,name:s.name,version:s.version,tools:l}}o.start=e;function n(){return Object.keys(chunkHY2LFKG7_cjs.x)}o.getToolNames=n;})(exports.b||(exports.b={}));exports.a=R;
64
+ `}]}}catch(a){return c(d(a),true)}}),n}var Ee={recall:chunk3EENVVWK_cjs.c,remember:chunk3EENVVWK_cjs.d,update:chunk3EENVVWK_cjs.e,forget:chunk3EENVVWK_cjs.f,extract:chunk3EENVVWK_cjs.g,consolidate:chunk3EENVVWK_cjs.h,sync:chunk3EENVVWK_cjs.m,graph_query:chunk3EENVVWK_cjs.i,status:chunk3EENVVWK_cjs.j,doctor:chunk3EENVVWK_cjs.k,init:chunk3EENVVWK_cjs.l};function xe(e,n){let o=chunk3EENVVWK_cjs.x[e],s={title:o?.annotations?.defaultDescription??e,readOnlyHint:o?.annotations?.readOnlyHint??false,destructiveHint:o?.annotations?.destructiveHint??false,idempotentHint:o?.annotations?.idempotentHint??true,openWorldHint:false},r=Ee[e];return {name:e,description:o?.annotations?.defaultDescription??`memory op: ${e}`,inputSchema:r??{type:"object",properties:{},required:[],additionalProperties:false},annotations:s,handler:n}}exports.b=void 0;(o=>{async function e(s,r){let{getMemoryDbPath:c,getInstance:d}=await import('./interfaces-BGC3V4WU.cjs'),a=r!==null&&typeof r=="object"&&"agentId"in r&&"dbPath"in r?r:{agentId:process.env.EASBOT_AGENT_ID??"default",dbPath:c(d().worktree),workspaceDir:d().worktree,isRemote:false};mcp.extendKnownErrorCodes(["AGENT_ID_REQUIRED","SESSION_ID_REQUIRED","CATEGORY_REQUIRED","IMPORTANCE_REQUIRED","TIMERANGE_REQUIRED","DRY_RUN_NO_DELETE"]);let m=new mcp.ToolRegistry,u=Te(a),l=Object.keys(chunk3EENVVWK_cjs.x);for(let y of l){let C=u.get(y);if(!C)throw new chunkAVECFV5K_cjs.a.MissingMcpHandlerError({message:`MemoryStdioServer.start: missing handler for tool "${y}"`,toolName:y});m.register(xe(y,C));}D.info("starting memory MCP stdio server",{id:s.id,name:s.name,toolCount:l.length,isRemote:a.isRemote??true});let i=await mcp.createAndStartStdioServer(s,m),f=null,p=new Promise(y=>{f=y;}),g=y=>{D.info("received signal, stopping MCP server",{signal:y}),f?.();},b=()=>g("SIGINT"),k=()=>g("SIGTERM"),L=(y,C)=>process.listeners(y).includes(C);L("SIGINT",b)||process.on("SIGINT",b),L("SIGTERM",k)||process.on("SIGTERM",k);try{await p;}finally{try{process.off("SIGINT",b),process.off("SIGTERM",k);}catch(y){D.warn("failed to remove signal handlers",{error:utils.errorMeta(y)});}try{await i.stop();}catch(y){D.warn("server.stop failed during cleanup",{error:utils.errorMeta(y)});}}return {id:s.id,name:s.name,version:s.version,tools:l}}o.start=e;function n(){return Object.keys(chunk3EENVVWK_cjs.x)}o.getToolNames=n;})(exports.b||(exports.b={}));exports.a=R;
@@ -0,0 +1 @@
1
+ import {f}from'./chunk-CIXJXCID.mjs';import {Log,errorMeta}from'@easbot/utils';import {renderLines,printHuman,emitJsonError,emitJsonOk,formatKnowledgeDoctor,formatKnowledgeStatus,formatKnowledgeInit}from'@easbot/terminal';var w=Log.create({service:"memory-cli"}),j=[{i18nKey:"cli.cmd.init.description",name:"init",description:"Initialize memory workspace (.easbot/memory.db)",group:"lifecycle"},{i18nKey:"cli.cmd.status.description",name:"status",description:"Show memory state / db stats / facts by category",group:"lifecycle"},{i18nKey:"cli.cmd.doctor.description",name:"doctor",description:"Run health checks (backend, FTS, schema, lock)",group:"lifecycle"},{i18nKey:"cli.cmd.recall.description",name:"recall",description:"Hybrid search (FTS + vector) over memory facts",group:"memory"},{i18nKey:"cli.cmd.remember.description",name:"remember",description:"Persist a new memory fact (with dedup + KG extraction)",group:"memory"},{i18nKey:"cli.cmd.forget.description",name:"forget",description:"Delete memory facts (factId / category / timeRange / dryRun)",group:"memory"},{i18nKey:"cli.cmd.sync.description",name:"sync",description:"Sync facts to .md files (idempotent) and archive expired active files (default 30 days)",group:"memory"},{i18nKey:"cli.cmd.extract.description",name:"extract",description:"Extract facts from a session (sessionId + lastN)",group:"session"},{i18nKey:"cli.cmd.consolidate.description",name:"consolidate",description:"Run consolidation pipeline (extract \u2192 dedup \u2192 archive)",group:"session"},{i18nKey:"cli.cmd.graph.description",name:"graph",description:"KG query (nodes / edges / neighbors with scope \u4E09\u6863)",group:"graph"},{i18nKey:"cli.cmd.config.description",name:"config",description:"Show / validate memory configuration (dry-read)",group:"external"},{i18nKey:"cli.cmd.mcp.description",name:"mcp",description:"Start stdio MCP server (exposes 10 memory tools)",group:"external"}];function g(p,t){let e=j.filter(s=>s.group===p);return renderLines({title:t,flat:e.map(s=>`$ easbot-memory ${s.name.padEnd(14)} ${s.description}`)})}function v(){let p=[renderLines({title:"easbot-memory \xB7 Memory & Knowledge Module for EASBot",flat:["Usage: easbot-memory <command> [options]"]}),"",g("lifecycle","Commands (lifecycle):"),"",g("memory","Commands (memory):"),"",g("session","Commands (session):"),"",g("graph","Commands (graph query):"),"",g("external","External:")];printHuman(p);}function C(){v(),printHuman(["",renderLines({title:"Global flags & invocation",flat:["--cwd <dir> --config <path> --log-level <L> --print-logs --debug","Standalone CLI: easbot-memory <command>","Agent CLI: easbot memory <command>"]})]);}async function K(p){try{let{bootstrapLlm:t}=await import('@easbot/llm'),{Llm:e}=await import('./llm-XHWMIOUN.mjs');await t({target:e,cwd:p,subConfigPath:".easbot/memory.json",embedding:!0,graph:!0});}catch(t){w.warn("bootstrapLlm failed; Llm-related features will be disabled",{error:errorMeta(t)});}}async function U(p,t){let[e,...s]=p,u=t?.cwd??process.cwd(),c=t?.agentId??"default";if(!e)return C(),{code:0,handled:true,command:null};await K(u);let l=s.includes("--json");try{switch(e){case "init":{let{parseInitOptions:i,runInit:a}=await import('./init-TTINBBT4.mjs'),n=i(s);if(n.help)return console.log("Usage: easbot-memory init [--force] [--json]"),{code:0,handled:!0,command:e};let o=await a({...n,agentId:c});if(n.json)emitJsonOk(o,{command:e});else {let r=o;printHuman([formatKnowledgeInit({packageName:"memory",configPath:r.configPath??r.dbPath,backend:"better-sqlite3",schemaVersion:r.schemaVersion,extras:{dbPath:r.dbPath,migrationsApplied:r.migrationsApplied,tablesCreated:r.tablesCreated,durationMs:`${r.durationMs}ms`}})],{title:"init memory workspace",boxed:!0});}return {code:0,handled:!0,command:e}}case "recall":{let{parseRecallOptions:i,runRecall:a,formatRecallText:n}=await import('./recall-JIH4PAR5.mjs'),o=i(s);if(o.help)return console.log("Usage: easbot-memory recall --query <q> [--limit <n>] [--category <c>] [--min-importance <n>] [--json]"),{code:0,handled:!0,command:e};let r=await a({...o,agentId:c});return o.json?emitJsonOk(r,{command:e}):printHuman([n(r)],{title:`recall (agentId=${c??"default"})`}),{code:0,handled:!0,command:e}}case "remember":{let{parseRememberOptions:i,runRemember:a,formatRememberText:n}=await import('./remember-KY4HDAE4.mjs'),o=i(s);if(o.help)return console.log("Usage: easbot-memory remember --content <text> --category <c> --importance <1-10> [--tag <t>] [--session <s>] [--json]"),{code:0,handled:!0,command:e};let r=await a({...o,agentId:c});return o.json?emitJsonOk(r,{command:e}):printHuman([n(r)],{title:"remember (persist fact)"}),{code:0,handled:!0,command:e}}case "forget":{let{parseForgetOptions:i,runForget:a,formatForgetText:n}=await import('./forget-PQLRSYOJ.mjs'),o=i(s);if(o.help)return console.log("Usage: easbot-memory forget (--fact-id <id> | --category <c> | --from <ISO> --to <ISO>) [--max-delete <n>] [--dry-run] [--json]"),{code:0,handled:!0,command:e};let r=await a({...o,agentId:c});return o.json?emitJsonOk(r,{command:e}):printHuman([n(r)],{title:"forget (delete facts)"}),{code:0,handled:!0,command:e}}case "extract":{let{parseExtractOptions:i,runExtract:a,formatExtractText:n}=await import('./extract-V4BIBFW7.mjs'),o=i(s);if(o.help)return console.log("Usage: easbot-memory extract --session <sessionId> [--last-n <n>] [--from-msg <id>] [--json]"),{code:0,handled:!0,command:e};let r=await a({...o,agentId:c});return o.json?emitJsonOk(r,{command:e}):printHuman([n(r)],{title:"extract (from session)"}),{code:0,handled:!0,command:e}}case "consolidate":{let{parseConsolidateOptions:i,runConsolidate:a,formatConsolidateText:n}=await import('./consolidate-ANQFG7QD.mjs'),o=i(s);if(o.help)return console.log("Usage: easbot-memory consolidate [--window-days <n>] [--json]"),{code:0,handled:!0,command:e};let r=await a({...o,agentId:c});return o.json?emitJsonOk(r,{command:e}):printHuman([n(r)],{title:"consolidate (pipeline)"}),{code:0,handled:!0,command:e}}case "sync":{let{parseSyncOptions:i,runSync:a,formatSyncText:n}=await import('./sync-D44EAJLK.mjs'),o=i(s);if(o.help)return console.log("Usage: easbot-memory sync [--window-days <n>] [--dry-run] [--json]"),console.log("Two-stage pipeline: (A) db \u2192 .md (idempotent skip on existing), (B) archive active/ files older than windowDays."),{code:0,handled:!0,command:e};let r=await a({...o,agentId:c});return o.json?emitJsonOk(r,{command:e}):printHuman([n(r)],{title:"sync (db \u2192 .md + archive)"}),{code:0,handled:!0,command:e}}case "graph":{let{parseGraphOptions:i,runGraph:a,formatGraphText:n}=await import('./graph-P6LEEEVA.mjs'),o=i(s);if(o.help)return console.log("Usage: easbot-memory graph [--query <q>] [--node-id <id>] [--max-depth <n>] [--max-nodes <n>] [--max-edges-per-node <n>] [--json]\n (note: `--depth` is an alias for `--max-depth`; old `--kind` / `--start-node` / `--scope` flags removed since service schema is strict)"),{code:0,handled:!0,command:e};let r=await a({...o,agentId:c});return o.json?emitJsonOk(r,{command:e}):printHuman([n(r)],{title:"graph_query"}),{code:0,handled:!0,command:e}}case "status":{let{parseStatusOptions:i,runStatus:a}=await import('./status-QZ27UQJG.mjs'),n=i(s);if(n.help)return console.log("Usage: easbot-memory status [--json]"),{code:0,handled:!0,command:e};let o=await a({...n,agentId:c});return n.json?emitJsonOk(o,{command:e}):printHuman([formatKnowledgeStatus(M(o))],{title:"memory status",boxed:!0}),{code:0,handled:!0,command:e}}case "doctor":{let{parseDoctorOptions:i,runDoctor:a}=await import('./doctor-CDS2OUAA.mjs'),n=i(s);if(n.help)return console.log("Usage: easbot-memory doctor [--repair] [--json]"),{code:0,handled:!0,command:e};let o=await a({...n});return n.json?emitJsonOk(o,{command:e}):printHuman([formatKnowledgeDoctor(R(o))],{title:"memory doctor",boxed:!0}),{code:0,handled:!0,command:e}}case "config":{let{parseConfigOptions:i,runConfig:a,formatConfigText:n}=await import('./config-2SQJYVTO.mjs'),o=i(s);if(o.help)return console.log("Usage: easbot-memory config [--json]"),{code:0,handled:!0,command:e};let r=a(o);return o.json?emitJsonOk(r,{command:e}):printHuman([n(r)],{title:"memory config"}),{code:0,handled:!0,command:e}}case "mcp":{let{parseMcpOptions:i,runMcp:a}=await import('./mcp-YNGRYILA.mjs'),n=i(s);if(n.help)return console.log("Usage: easbot-memory mcp [start]"),console.log("Start a stdio MCP server exposing 10 memory tools:"),console.log(" recall / remember / forget / extract / consolidate"),console.log(" graph_query / status / doctor / init / sync"),{code:0,handled:!0,command:e};let o=await a(n);return n.json?emitJsonOk(o,{command:e}):printHuman([`memory mcp started (tools: ${o.tools.length})`],{title:"memory mcp server"}),{code:0,handled:!0,command:e}}default:return l?emitJsonError(e??"__unknown__",`Unknown command: ${e}`):(console.error(`Unknown command: ${e}`),console.error("Run `easbot-memory --help` for available commands.")),{code:2,handled:!1,command:null}}}catch(i){let a=errorMeta(i);w.error("memory CLI command failed",{command:e,error:a});let n=t?.cwd??f().worktree;return l?emitJsonError(e??"__unknown__",a.message):console.error(`[memory] ${n} :: ${e} failed: ${a.message}`),{code:1,handled:true,command:e}}}function M(p){let t=p;return {packageName:"memory",rootDir:t.workspaceDir??"",configPath:t.configPath??"",configExists:typeof t.configExists=="boolean"?t.configExists:true,dbPath:t.dbPath??"",dbExists:typeof t.dbExists=="boolean"?t.dbExists:true,dbSize:typeof t.dbSize=="number"?t.dbSize:void 0,indexState:t.indexState,schemaVersion:typeof t.schemaVersion=="number"?t.schemaVersion:void 0,extractionVersion:typeof t.extractionVersion=="number"?t.extractionVersion:void 0,lastSyncAt:t.lastSyncAt,vectorEnabled:typeof t.vectorEnabled=="boolean"?t.vectorEnabled:void 0,embeddingDims:typeof t.embeddingDims=="number"?t.embeddingDims:void 0,llm:t.llm??{initialized:false,capabilities:{}},backend:t.backend,healthy:typeof t.healthy=="boolean"?t.healthy:true,recommendation:t.recommendation,dbStats:(()=>{let e=t.dbStats;if(e&&typeof e=="object"&&Object.keys(e).length>0)return {...e};let s=t.integrityStats;if(s&&typeof s=="object"&&Object.keys(s).length>0)return {...s}})(),extras:(()=>{let e={};if(typeof t.agentId=="string"&&(e.agent_id=t.agentId),typeof t.ftsAvailable=="boolean"&&(e.fts_available=t.ftsAvailable?"yes":"no"),t.factsByCategory&&typeof t.factsByCategory=="object"){let s=t.factsByCategory;for(let[u,c]of Object.entries(s))typeof c=="number"&&c>0&&(e[`facts/${u}`]=c);}if(t.meta&&typeof t.meta=="object")for(let[s,u]of Object.entries(t.meta))e[`meta/${s}`]=u===void 0?"\u2205":u;return Object.keys(e).length>0?e:void 0})()}}function R(p){let t=p,e=Array.isArray(t.checks)?t.checks:[],s=t.integrityStats,u=t.backendAvailable,c=s?{...s}:void 0;return {packageName:"memory",healthy:typeof t.healthy=="boolean"?t.healthy:false,durationMs:typeof t.durationMs=="number"?t.durationMs:0,checks:e.map(l=>({code:typeof l.code=="string"?l.code:"",severity:l.severity??"info",name:typeof l.name=="string"?l.name:"",message:typeof l.message=="string"?l.message:"",durationMs:typeof l.durationMs=="number"?l.durationMs:void 0,details:l.details})),dbStats:c,backendAvailable:u}}export{j as a,v as b,C as c,U as d,R as e};
@@ -0,0 +1 @@
1
+ 'use strict';var os=require('os'),utils=require('@easbot/utils'),xdgBasedir=require('xdg-basedir');var n=null,r=null;function b(e){n=e;}function d(){n=null;}function a(){if(n)return n;let e=utils.Filesystem.normalize(os.homedir());return {Path:{home:e,data:process.env.EASBOT_DATA_PATH?.trim()||utils.Filesystem.join(xdgBasedir.xdgData??utils.Filesystem.join(e,".local","share"),"easbot"),config:process.env.EASBOT_CONFIG_PATH?.trim()||utils.Filesystem.join(e,".config","easbot"),state:process.env.EASBOT_STATE_PATH?.trim()||utils.Filesystem.join(xdgBasedir.xdgData??utils.Filesystem.join(e,".local","share"),"easbot","state"),cache:process.env.EASBOT_CACHE_PATH?.trim()||utils.Filesystem.join(e,".cache","easbot"),log:process.env.EASBOT_LOG_PATH?.trim()||utils.Filesystem.join(xdgBasedir.xdgData??utils.Filesystem.join(e,".local","share"),"easbot","log"),bin:process.env.EASBOT_BIN_PATH?.trim()||utils.Filesystem.join(e,".local","bin")}}}function f(e){r=e;}function A(){r=null;}function I(){if(r)return r;let e=utils.Filesystem.normalize(process.cwd());return {directory:e,worktree:e}}function s(){return utils.Filesystem.normalize(a().Path.home||os.homedir())}function l(){let e=a().Path.data;return e||(xdgBasedir.xdgData??utils.Filesystem.join(s(),".local","share"))}function g(){return utils.Filesystem.join(l(),"memory")}function T(e){return utils.Filesystem.join(e,".easbot","db","memory.db")}exports.a=b;exports.b=d;exports.c=a;exports.d=f;exports.e=A;exports.f=I;exports.g=s;exports.h=l;exports.i=g;exports.j=T;
@@ -0,0 +1 @@
1
+ 'use strict';var chunkGHJLFUKH_cjs=require('./chunk-GHJLFUKH.cjs'),utils=require('@easbot/utils'),terminal=require('@easbot/terminal');var w=utils.Log.create({service:"memory-cli"}),j=[{i18nKey:"cli.cmd.init.description",name:"init",description:"Initialize memory workspace (.easbot/memory.db)",group:"lifecycle"},{i18nKey:"cli.cmd.status.description",name:"status",description:"Show memory state / db stats / facts by category",group:"lifecycle"},{i18nKey:"cli.cmd.doctor.description",name:"doctor",description:"Run health checks (backend, FTS, schema, lock)",group:"lifecycle"},{i18nKey:"cli.cmd.recall.description",name:"recall",description:"Hybrid search (FTS + vector) over memory facts",group:"memory"},{i18nKey:"cli.cmd.remember.description",name:"remember",description:"Persist a new memory fact (with dedup + KG extraction)",group:"memory"},{i18nKey:"cli.cmd.forget.description",name:"forget",description:"Delete memory facts (factId / category / timeRange / dryRun)",group:"memory"},{i18nKey:"cli.cmd.sync.description",name:"sync",description:"Sync facts to .md files (idempotent) and archive expired active files (default 30 days)",group:"memory"},{i18nKey:"cli.cmd.extract.description",name:"extract",description:"Extract facts from a session (sessionId + lastN)",group:"session"},{i18nKey:"cli.cmd.consolidate.description",name:"consolidate",description:"Run consolidation pipeline (extract \u2192 dedup \u2192 archive)",group:"session"},{i18nKey:"cli.cmd.graph.description",name:"graph",description:"KG query (nodes / edges / neighbors with scope \u4E09\u6863)",group:"graph"},{i18nKey:"cli.cmd.config.description",name:"config",description:"Show / validate memory configuration (dry-read)",group:"external"},{i18nKey:"cli.cmd.mcp.description",name:"mcp",description:"Start stdio MCP server (exposes 10 memory tools)",group:"external"}];function g(p,t){let e=j.filter(s=>s.group===p);return terminal.renderLines({title:t,flat:e.map(s=>`$ easbot-memory ${s.name.padEnd(14)} ${s.description}`)})}function v(){let p=[terminal.renderLines({title:"easbot-memory \xB7 Memory & Knowledge Module for EASBot",flat:["Usage: easbot-memory <command> [options]"]}),"",g("lifecycle","Commands (lifecycle):"),"",g("memory","Commands (memory):"),"",g("session","Commands (session):"),"",g("graph","Commands (graph query):"),"",g("external","External:")];terminal.printHuman(p);}function C(){v(),terminal.printHuman(["",terminal.renderLines({title:"Global flags & invocation",flat:["--cwd <dir> --config <path> --log-level <L> --print-logs --debug","Standalone CLI: easbot-memory <command>","Agent CLI: easbot memory <command>"]})]);}async function K(p){try{let{bootstrapLlm:t}=await import('@easbot/llm'),{Llm:e}=await import('./llm-RSSNHF6T.cjs');await t({target:e,cwd:p,subConfigPath:".easbot/memory.json",embedding:!0,graph:!0});}catch(t){w.warn("bootstrapLlm failed; Llm-related features will be disabled",{error:utils.errorMeta(t)});}}async function P(p,t){let[e,...s]=p,u=t?.cwd??process.cwd(),c=t?.agentId??"default";if(!e)return C(),{code:0,handled:true,command:null};await K(u);let l=s.includes("--json");try{switch(e){case "init":{let{parseInitOptions:i,runInit:a}=await import('./init-7SHKOGVZ.cjs'),n=i(s);if(n.help)return console.log("Usage: easbot-memory init [--force] [--json]"),{code:0,handled:!0,command:e};let o=await a({...n,agentId:c});if(n.json)terminal.emitJsonOk(o,{command:e});else {let r=o;terminal.printHuman([terminal.formatKnowledgeInit({packageName:"memory",configPath:r.configPath??r.dbPath,backend:"better-sqlite3",schemaVersion:r.schemaVersion,extras:{dbPath:r.dbPath,migrationsApplied:r.migrationsApplied,tablesCreated:r.tablesCreated,durationMs:`${r.durationMs}ms`}})],{title:"init memory workspace",boxed:!0});}return {code:0,handled:!0,command:e}}case "recall":{let{parseRecallOptions:i,runRecall:a,formatRecallText:n}=await import('./recall-TA4YPWD2.cjs'),o=i(s);if(o.help)return console.log("Usage: easbot-memory recall --query <q> [--limit <n>] [--category <c>] [--min-importance <n>] [--json]"),{code:0,handled:!0,command:e};let r=await a({...o,agentId:c});return o.json?terminal.emitJsonOk(r,{command:e}):terminal.printHuman([n(r)],{title:`recall (agentId=${c??"default"})`}),{code:0,handled:!0,command:e}}case "remember":{let{parseRememberOptions:i,runRemember:a,formatRememberText:n}=await import('./remember-5JAWVMYX.cjs'),o=i(s);if(o.help)return console.log("Usage: easbot-memory remember --content <text> --category <c> --importance <1-10> [--tag <t>] [--session <s>] [--json]"),{code:0,handled:!0,command:e};let r=await a({...o,agentId:c});return o.json?terminal.emitJsonOk(r,{command:e}):terminal.printHuman([n(r)],{title:"remember (persist fact)"}),{code:0,handled:!0,command:e}}case "forget":{let{parseForgetOptions:i,runForget:a,formatForgetText:n}=await import('./forget-FG7ZFJL7.cjs'),o=i(s);if(o.help)return console.log("Usage: easbot-memory forget (--fact-id <id> | --category <c> | --from <ISO> --to <ISO>) [--max-delete <n>] [--dry-run] [--json]"),{code:0,handled:!0,command:e};let r=await a({...o,agentId:c});return o.json?terminal.emitJsonOk(r,{command:e}):terminal.printHuman([n(r)],{title:"forget (delete facts)"}),{code:0,handled:!0,command:e}}case "extract":{let{parseExtractOptions:i,runExtract:a,formatExtractText:n}=await import('./extract-3MLEFVJV.cjs'),o=i(s);if(o.help)return console.log("Usage: easbot-memory extract --session <sessionId> [--last-n <n>] [--from-msg <id>] [--json]"),{code:0,handled:!0,command:e};let r=await a({...o,agentId:c});return o.json?terminal.emitJsonOk(r,{command:e}):terminal.printHuman([n(r)],{title:"extract (from session)"}),{code:0,handled:!0,command:e}}case "consolidate":{let{parseConsolidateOptions:i,runConsolidate:a,formatConsolidateText:n}=await import('./consolidate-GJPX4H7R.cjs'),o=i(s);if(o.help)return console.log("Usage: easbot-memory consolidate [--window-days <n>] [--json]"),{code:0,handled:!0,command:e};let r=await a({...o,agentId:c});return o.json?terminal.emitJsonOk(r,{command:e}):terminal.printHuman([n(r)],{title:"consolidate (pipeline)"}),{code:0,handled:!0,command:e}}case "sync":{let{parseSyncOptions:i,runSync:a,formatSyncText:n}=await import('./sync-SJI7PENR.cjs'),o=i(s);if(o.help)return console.log("Usage: easbot-memory sync [--window-days <n>] [--dry-run] [--json]"),console.log("Two-stage pipeline: (A) db \u2192 .md (idempotent skip on existing), (B) archive active/ files older than windowDays."),{code:0,handled:!0,command:e};let r=await a({...o,agentId:c});return o.json?terminal.emitJsonOk(r,{command:e}):terminal.printHuman([n(r)],{title:"sync (db \u2192 .md + archive)"}),{code:0,handled:!0,command:e}}case "graph":{let{parseGraphOptions:i,runGraph:a,formatGraphText:n}=await import('./graph-34HVP7TP.cjs'),o=i(s);if(o.help)return console.log("Usage: easbot-memory graph [--query <q>] [--node-id <id>] [--max-depth <n>] [--max-nodes <n>] [--max-edges-per-node <n>] [--json]\n (note: `--depth` is an alias for `--max-depth`; old `--kind` / `--start-node` / `--scope` flags removed since service schema is strict)"),{code:0,handled:!0,command:e};let r=await a({...o,agentId:c});return o.json?terminal.emitJsonOk(r,{command:e}):terminal.printHuman([n(r)],{title:"graph_query"}),{code:0,handled:!0,command:e}}case "status":{let{parseStatusOptions:i,runStatus:a}=await import('./status-YGRSKKZZ.cjs'),n=i(s);if(n.help)return console.log("Usage: easbot-memory status [--json]"),{code:0,handled:!0,command:e};let o=await a({...n,agentId:c});return n.json?terminal.emitJsonOk(o,{command:e}):terminal.printHuman([terminal.formatKnowledgeStatus(M(o))],{title:"memory status",boxed:!0}),{code:0,handled:!0,command:e}}case "doctor":{let{parseDoctorOptions:i,runDoctor:a}=await import('./doctor-4L2KSJXV.cjs'),n=i(s);if(n.help)return console.log("Usage: easbot-memory doctor [--repair] [--json]"),{code:0,handled:!0,command:e};let o=await a({...n});return n.json?terminal.emitJsonOk(o,{command:e}):terminal.printHuman([terminal.formatKnowledgeDoctor(R(o))],{title:"memory doctor",boxed:!0}),{code:0,handled:!0,command:e}}case "config":{let{parseConfigOptions:i,runConfig:a,formatConfigText:n}=await import('./config-I2I6U4XM.cjs'),o=i(s);if(o.help)return console.log("Usage: easbot-memory config [--json]"),{code:0,handled:!0,command:e};let r=a(o);return o.json?terminal.emitJsonOk(r,{command:e}):terminal.printHuman([n(r)],{title:"memory config"}),{code:0,handled:!0,command:e}}case "mcp":{let{parseMcpOptions:i,runMcp:a}=await import('./mcp-7TMDANN6.cjs'),n=i(s);if(n.help)return console.log("Usage: easbot-memory mcp [start]"),console.log("Start a stdio MCP server exposing 10 memory tools:"),console.log(" recall / remember / forget / extract / consolidate"),console.log(" graph_query / status / doctor / init / sync"),{code:0,handled:!0,command:e};let o=await a(n);return n.json?terminal.emitJsonOk(o,{command:e}):terminal.printHuman([`memory mcp started (tools: ${o.tools.length})`],{title:"memory mcp server"}),{code:0,handled:!0,command:e}}default:return l?terminal.emitJsonError(e??"__unknown__",`Unknown command: ${e}`):(console.error(`Unknown command: ${e}`),console.error("Run `easbot-memory --help` for available commands.")),{code:2,handled:!1,command:null}}}catch(i){let a=utils.errorMeta(i);w.error("memory CLI command failed",{command:e,error:a});let n=t?.cwd??chunkGHJLFUKH_cjs.f().worktree;return l?terminal.emitJsonError(e??"__unknown__",a.message):console.error(`[memory] ${n} :: ${e} failed: ${a.message}`),{code:1,handled:true,command:e}}}function M(p){let t=p;return {packageName:"memory",rootDir:t.workspaceDir??"",configPath:t.configPath??"",configExists:typeof t.configExists=="boolean"?t.configExists:true,dbPath:t.dbPath??"",dbExists:typeof t.dbExists=="boolean"?t.dbExists:true,dbSize:typeof t.dbSize=="number"?t.dbSize:void 0,indexState:t.indexState,schemaVersion:typeof t.schemaVersion=="number"?t.schemaVersion:void 0,extractionVersion:typeof t.extractionVersion=="number"?t.extractionVersion:void 0,lastSyncAt:t.lastSyncAt,vectorEnabled:typeof t.vectorEnabled=="boolean"?t.vectorEnabled:void 0,embeddingDims:typeof t.embeddingDims=="number"?t.embeddingDims:void 0,llm:t.llm??{initialized:false,capabilities:{}},backend:t.backend,healthy:typeof t.healthy=="boolean"?t.healthy:true,recommendation:t.recommendation,dbStats:(()=>{let e=t.dbStats;if(e&&typeof e=="object"&&Object.keys(e).length>0)return {...e};let s=t.integrityStats;if(s&&typeof s=="object"&&Object.keys(s).length>0)return {...s}})(),extras:(()=>{let e={};if(typeof t.agentId=="string"&&(e.agent_id=t.agentId),typeof t.ftsAvailable=="boolean"&&(e.fts_available=t.ftsAvailable?"yes":"no"),t.factsByCategory&&typeof t.factsByCategory=="object"){let s=t.factsByCategory;for(let[u,c]of Object.entries(s))typeof c=="number"&&c>0&&(e[`facts/${u}`]=c);}if(t.meta&&typeof t.meta=="object")for(let[s,u]of Object.entries(t.meta))e[`meta/${s}`]=u===void 0?"\u2205":u;return Object.keys(e).length>0?e:void 0})()}}function R(p){let t=p,e=Array.isArray(t.checks)?t.checks:[],s=t.integrityStats,u=t.backendAvailable,c=s?{...s}:void 0;return {packageName:"memory",healthy:typeof t.healthy=="boolean"?t.healthy:false,durationMs:typeof t.durationMs=="number"?t.durationMs:0,checks:e.map(l=>({code:typeof l.code=="string"?l.code:"",severity:l.severity??"info",name:typeof l.name=="string"?l.name:"",message:typeof l.message=="string"?l.message:"",durationMs:typeof l.durationMs=="number"?l.durationMs:void 0,details:l.details})),dbStats:c,backendAvailable:u}}exports.a=j;exports.b=v;exports.c=C;exports.d=P;exports.e=R;
@@ -1,24 +1,24 @@
1
- import {x,z,l,k as k$1,j as j$1,i,m,h,g,f,e,d,c,A as A$1}from'./chunk-X7P7ZFZF.mjs';import {extendKnownErrorCodes,ToolRegistry,createAndStartStdioServer,formatFailClosed}from'@easbot/mcp';import {Log,Locale,TruncateContent}from'@easbot/utils';var ae=Log.create({service:"memory-format-truncate"}),X="**`";var Z=24e3,ee=25e3;async function $(e,n={}){let o=n.softLimit??Z,s=n.hardCeiling??ee,r=n.toolName??"memory",c=n.writeToDisk!==false;if(e.length<=o)return {content:e,truncated:false};let d=e.slice(0,s),t=d.lastIndexOf(`
2
- ${X}`),a=d.lastIndexOf(`
3
- `),m;t>s*.5?m=t:a>0?m=a:m=-1;let u=m>0?d.slice(0,m):d,i=u+"\n\n... (output truncated to budget; the source above is complete and verbatim \u2014 treat it as already Read. For any area not covered, make ANOTHER `<tool>` targeting those names \u2014 do NOT Read these files.)";if(!c)return {content:i,truncated:true,outputPath:"",hint:"Make another recall / graph_query with narrower scope.",info:`... ${e.length-u.length}/${e.length} characters truncated ...`};try{let p=await TruncateContent.truncate(e,{maxChars:u.length,direction:"head",label:`${r}-output`});return p.truncated?{content:i,truncated:!0,outputPath:p.outputPath,hint:TruncateContent.formatHint(p),info:`... ${p.removedLength}/${p.originalLength} characters truncated ...`}:{content:i,truncated:!0,outputPath:"",hint:"Make another recall / graph_query with narrower scope.",info:`... ${e.length-u.length}/${e.length} characters truncated ...`}}catch(p){return ae.warn("TruncateContent.truncate failed, returning without disk hint",{error:p instanceof Error?p.message:String(p)}),{content:i,truncated:true,outputPath:"",hint:"Make another recall / graph_query with narrower scope.",info:`... ${e.length-u.length}/${e.length} characters truncated ...`}}}function w(e,n={}){let o=n.softLimit??Z,s=n.hardCeiling??ee;if(e.length<=o)return {content:e,truncated:false};let r=e.slice(0,s),c=r.lastIndexOf(`
4
- ${X}`),d=r.lastIndexOf(`
1
+ import {x,z,l,k as k$1,j as j$1,i,m,h,g,f,e,d,c,A as A$1}from'./chunk-OOBYBPIN.mjs';import {a}from'./chunk-AJDMZTCQ.mjs';import {extendKnownErrorCodes,ToolRegistry,createAndStartStdioServer,formatFailClosed}from'@easbot/mcp';import {Log,errorMeta,Locale,TruncateContent}from'@easbot/utils';var de=Log.create({service:"memory-format-truncate"}),Z="**`";var ee=24e3,te=25e3;async function $(e,n={}){let o=n.softLimit??ee,s=n.hardCeiling??te,r=n.toolName??"memory",c=n.writeToDisk!==false;if(e.length<=o)return {content:e,truncated:false};let d=e.slice(0,s),t=d.lastIndexOf(`
2
+ ${Z}`),a=d.lastIndexOf(`
3
+ `),m;t>s*.5?m=t:a>0?m=a:m=-1;let u=m>0?d.slice(0,m):d,i=u+"\n\n... (output truncated to budget; the source above is complete and verbatim \u2014 treat it as already Read. For any area not covered, make ANOTHER `<tool>` targeting those names \u2014 do NOT Read these files.)";if(!c)return {content:i,truncated:true,outputPath:"",hint:"Make another recall / graph_query with narrower scope.",info:`... ${e.length-u.length}/${e.length} characters truncated ...`};try{let f=await TruncateContent.truncate(e,{maxChars:u.length,direction:"head",label:`${r}-output`});return f.truncated?{content:i,truncated:!0,outputPath:f.outputPath,hint:TruncateContent.formatHint(f),info:`... ${f.removedLength}/${f.originalLength} characters truncated ...`}:{content:i,truncated:!0,outputPath:"",hint:"Make another recall / graph_query with narrower scope.",info:`... ${e.length-u.length}/${e.length} characters truncated ...`}}catch(f){return de.warn("TruncateContent.truncate failed, returning without disk hint",{error:errorMeta(f)}),{content:i,truncated:true,outputPath:"",hint:"Make another recall / graph_query with narrower scope.",info:`... ${e.length-u.length}/${e.length} characters truncated ...`}}}function w(e,n={}){let o=n.softLimit??ee,s=n.hardCeiling??te;if(e.length<=o)return {content:e,truncated:false};let r=e.slice(0,s),c=r.lastIndexOf(`
4
+ ${Z}`),d=r.lastIndexOf(`
5
5
  `),t;c>s*.5?t=c:d>0?t=d:t=-1;let a=t>0?r.slice(0,t):r;return {content:a+`
6
6
 
7
- ... (output truncated; tail dropped at section boundary)`,truncated:true,outputPath:"",hint:"",info:`... ${e.length-a.length}/${e.length} characters truncated ...`}}function se(e,n){if(!e||e.length===0)return null;let o=e.filter(r=>n.has(r.path));return o.length===0?null:`\u26A0\uFE0F Index may be stale for: ${o.map(r=>`${r.path} (edited pending)`).join(", ")}
7
+ ... (output truncated; tail dropped at section boundary)`,truncated:true,outputPath:"",hint:"",info:`... ${e.length-a.length}/${e.length} characters truncated ...`}}function ce(e,n){if(!e||e.length===0)return null;let o=e.filter(r=>n.has(r.path));return o.length===0?null:`\u26A0\uFE0F Index may be stale for: ${o.map(r=>`${r.path} (edited pending)`).join(", ")}
8
8
 
9
- `}function I(e,n,o={}){return (te[e]??te.default).replace(/<(\w+)>/g,(r,c)=>c==="tool"?n:o[c]??`<${c}>`)}var te={recall:"If you need more facts, make ANOTHER `<tool>` query with a different scope / interval.\nIf you have enough context, proceed with the current task. Do NOT call `<tool>` again for the same query.",remember:"Memory persisted. To recall it later, use `<tool>` with the same query.\nDo NOT call `<tool>` again to verify \u2014 the fact is already in the database.",forget:"Memory deleted. To verify, run `<tool>` with the same filter (no results expected).\nIf you deleted too much, the data is gone (no auto-restore).",graph_query:"If you need to explore further, make ANOTHER `<tool>` from a different start node or depth.\nOtherwise, the graph is complete for this scope.",status:"Status snapshot. To inspect a specific fact, use `<tool>` (recall) with its id.\nOtherwise, this is a complete read.",consolidate:"Consolidation done. To inspect the new facts, use `<tool>` with the same agentId.\nIf you want to undo, archives are in <archive_dir>.",doctor:"Doctor report. To fix a failing check, run with `repair=true`.\nRe-run after fix to confirm.",default:"If you need more, make ANOTHER `<tool>` with refined parameters.\nOtherwise, this is a complete read."};function ie(e){let n=Array.isArray(e.edges)?e.edges.length:0;return ` - node #${e.id}: ${e.name} (${e.type}) [edges: ${n}]`}function ne(e,n,o,s){let r=e.tags&&e.tags.length>0?`
9
+ `}function I(e,n,o={}){return (ne[e]??ne.default).replace(/<(\w+)>/g,(r,c)=>c==="tool"?n:o[c]??`<${c}>`)}var ne={recall:"If you need more facts, make ANOTHER `<tool>` query with a different scope / interval.\nIf you have enough context, proceed with the current task. Do NOT call `<tool>` again for the same query.",remember:"Memory persisted. To recall it later, use `<tool>` with the same query.\nDo NOT call `<tool>` again to verify \u2014 the fact is already in the database.",forget:"Memory deleted. To verify, run `<tool>` with the same filter (no results expected).\nIf you deleted too much, the data is gone (no auto-restore).",graph_query:"If you need to explore further, make ANOTHER `<tool>` from a different start node or depth.\nOtherwise, the graph is complete for this scope.",status:"Status snapshot. To inspect a specific fact, use `<tool>` (recall) with its id.\nOtherwise, this is a complete read.",consolidate:"Consolidation done. To inspect the new facts, use `<tool>` with the same agentId.\nIf you want to undo, archives are in <archive_dir>.",doctor:"Doctor report. To fix a failing check, run with `repair=true`.\nRe-run after fix to confirm.",default:"If you need more, make ANOTHER `<tool>` with refined parameters.\nOtherwise, this is a complete read."};function ue(e){let n=Array.isArray(e.edges)?e.edges.length:0;return ` - node #${e.id}: ${e.name} (${e.type}) [edges: ${n}]`}function re(e,n,o,s){let r=e.tags&&e.tags.length>0?`
10
10
  - tags: ${e.tags.join(", ")}`:"",c=e.sessionId?`
11
11
  - session: ${e.sessionId}`:"",d=e.msgId?`
12
12
  - msg: ${e.msgId}`:"",t=typeof n=="number"?`
13
- - score: ${n.toFixed(3)}${o?` (${o})`:""}`:"",a=e.truncated?" [truncated]":"",m="";if(s&&s.length>0){let u=s.map(ie);m=`
13
+ - score: ${n.toFixed(3)}${o?` (${o})`:""}`:"",a=e.truncated?" [truncated]":"",m="";if(s&&s.length>0){let u=s.map(ue);m=`
14
14
  - linked KG nodes (${s.length}) \u2014 use \`graph_query(nodeId=<id>)\` for full relation graph:
15
15
  ${u.join(`
16
16
  `)}`;}return [`### \`${e.id}\`${a}`,` - agentId: ${e.agentId}`,` - category: ${e.category}`,` - importance: ${e.importance}`,` - createdAt: ${e.createdAt}`,` - updatedAt: ${e.updatedAt}`,` - source: ${e.source}${t}${r}${c}${d}${m}`,"",e.content,""].join(`
17
- `)}async function v(e,n){let o=n.toolName??"memory_recall",s=`**\`memory_recall:${n.query.slice(0,40).replace(/[^a-zA-Z0-9_]/g,"_")}\`**`,r=se(n.pendingFiles,new Set),d=[`Found ${e.total} fact(s) for query "${n.query}" (agentId=${n.agentId}, scope=${n.scope}):`,"",r??"",s].join(`
18
- `),t=new Map;for(let l of e.hits){let i=l.fact.category;t.has(i)||t.set(i,[]),t.get(i).push(l);}let a=Array.from(t.entries()).map(([l,i])=>{let p=`**\`category:${l}\`**`,h=i.map(f=>ne(f.fact,f.score,f.source,f.nodes)).join(`
19
- `);return `${p}
17
+ `)}async function M(e,n){let o=n.toolName??"memory_recall",s=`**\`memory_recall:${n.query.slice(0,40).replace(/[^a-zA-Z0-9_]/g,"_")}\`**`,r=ce(n.pendingFiles,new Set),d=[`Found ${e.total} fact(s) for query "${n.query}" (agentId=${n.agentId}, scope=${n.scope}):`,"",r??"",s].join(`
18
+ `),t=new Map;for(let l of e.hits){let i=l.fact.category;t.has(i)||t.set(i,[]),t.get(i).push(l);}let a=Array.from(t.entries()).map(([l,i])=>{let f=`**\`category:${l}\`**`,p=i.map(g=>re(g.fact,g.score,g.source,g.nodes)).join(`
19
+ `);return `${f}
20
20
 
21
- ${h}`}).join(`
21
+ ${p}`}).join(`
22
22
  `),m=e.warnings&&e.warnings.length>0?`
23
23
 
24
24
  \u26A0\uFE0F warnings:
@@ -28,7 +28,7 @@ ${e.warnings.map(l=>` - ${l}`).join(`
28
28
 
29
29
  ${a}${m}
30
30
 
31
- ${I("recall",o)}`;return n.sync?w(u,{}).content:(await $(u,{toolName:o,writeToDisk:n.writeToDisk})).content}async function A(e,n={}){let o=n.toolName??"memory_remember",s=`**\`memory_remember:${e.fact.id}\`**`,r=ne(e.fact),c=e.nodeIds??[],d=c.length>0?`
31
+ ${I("recall",o)}`;return n.sync?w(u,{}).content:(await $(u,{toolName:o,writeToDisk:n.writeToDisk})).content}async function A(e,n={}){let o=n.toolName??"memory_remember",s=`**\`memory_remember:${e.fact.id}\`**`,r=re(e.fact),c=e.nodeIds??[],d=c.length>0?`
32
32
  - linked KG nodes: ${c.join(", ")}
33
33
  `:"",t=`${s}
34
34
 
@@ -40,12 +40,12 @@ ${e.deletedIds.map(t=>` - ${t}`).join(`
40
40
  `);return n.sync?w(d,{}).content:(await $(d,{toolName:o,writeToDisk:n.writeToDisk})).content}async function N(e,n={}){let o=n.toolName??"memory_graph_query",s=`**\`memory_graph_query:scope=${e.scope}\`**`,r=e.nodes.map(t=>` - node #${t.id}: ${t.name} (${t.type})${t.ownerAgentId?` [owner=${t.ownerAgentId}]`:" [shared]"}`).join(`
41
41
  `),c=e.edges.map(t=>` - edge #${t.id}: ${t.source} --${t.relation}--> ${t.target}`).join(`
42
42
  `),d=[s,"",`nodes (${e.nodes.length}${e.truncated?` / total ${e.totalNodes}`:""}):`,r||" (none)","",`edges (${e.edges.length}${e.truncated?` / total ${e.totalEdges}`:""}):`,c||" (none)","",I("graph_query",o)].join(`
43
- `);return n.sync?w(d,{}).content:(await $(d,{toolName:o,writeToDisk:n.writeToDisk})).content}async function M(e,n={}){let o=n.toolName??"memory_status",r=["**`memory_status`**","",`dbPath: ${e.dbPath}`,`workspaceDir: ${e.workspaceDir}`,`factsCount: ${e.factsCount}`,`nodesCount: ${e.nodesCount} (KG nodes)`,`edgesCount: ${e.edgesCount} (KG edges)`,`ftsAvailable: ${e.ftsAvailable?"yes":"no"}`,`vectorEnabled: ${e.vectorEnabled?"yes":"no"}`,`healthy: ${e.healthy?"yes":"no"}`,"","factsByCategory:",...Object.entries(e.factsByCategory).map(([d,t])=>` - ${d}: ${t}`),"","meta:",...Object.entries(e.meta).map(([d,t])=>` - ${d}: ${t}`)];if(e.integrityStats&&Object.keys(e.integrityStats).length>0){r.push("","DB stats:");let d=Math.max(...Object.keys(e.integrityStats).map(t=>t.length));for(let[t,a]of Object.entries(e.integrityStats))r.push(` - ${t.padEnd(d)} ${a}`);}r.push("",I("status",o));let c=r.join(`
44
- `);return n.sync?w(c,{}).content:(await $(c,{toolName:o,writeToDisk:n.writeToDisk})).content}async function O(e,n={}){let o=n.toolName??"memory_consolidate",r=["**`memory_consolidate:result`**","",`total facts scanned: ${e.totalFacts}`,`deduped (merged): ${e.dedupedCount}`,`compressed: ${e.compressedCount}`,`archived to archive/: ${e.archivedCount}`,`skipped (no change): ${e.skippedCount}`,`duration: ${e.durationMs}ms`,"",I("consolidate",o)].join(`
45
- `);return n.sync?w(r,{}).content:(await $(r,{toolName:o,writeToDisk:n.writeToDisk})).content}var k=20;async function P(e,n={}){let o=n.toolName??"memory_sync",r=[`**\`memory_sync:${e.dryRun?"DRY_RUN":"OK"}\`**`,"",`windowDays: ${e.windowDays} (threshold: ${e.archiveThreshold})`,"","## Stage A (db \u2192 .md)",`- generated: ${e.generatedCount}`,`- skipped (idempotent): ${e.skippedCount}`,`- failed (best-effort): ${e.failedGenerateCount}`,"","## Stage B (active/ \u2192 archive/)",`- ${e.dryRun?"would archive":"archived"}: ${e.archivedCount}`];if(e.archivedRecords.length>0){r.push("","### Archived records:");let d=e.archivedRecords.slice(0,k);for(let t of d)r.push(`- ${t.firstFactId} (${t.firstCreatedAt})`),r.push(` - source: \`${t.source}\``),r.push(` - target: \`${t.target}\``);e.archivedRecords.length>k&&r.push(`... and ${e.archivedRecords.length-k} more (use --json for full list)`);}r.push("",`duration: ${e.durationMs}ms`,"",I("sync",o));let c=r.join(`
46
- `);return n.sync?w(c,{}).content:(await $(c,{toolName:o,writeToDisk:n.writeToDisk})).content}async function j(e,n={}){let o=n.toolName??"memory_doctor",s=`**\`memory_doctor:${e.healthy?"OK":"ISSUES"}\`**`,r=t=>t?"\u2705":"\u274C",c=e.checks.map(t=>`${r(t.passed)} ${t.name}: ${t.message}`).join(`
43
+ `);return n.sync?w(d,{}).content:(await $(d,{toolName:o,writeToDisk:n.writeToDisk})).content}async function O(e,n={}){let o=n.toolName??"memory_status",r=["**`memory_status`**","",`dbPath: ${e.dbPath}`,`workspaceDir: ${e.workspaceDir}`,`factsCount: ${e.factsCount}`,`nodesCount: ${e.nodesCount} (KG nodes)`,`edgesCount: ${e.edgesCount} (KG edges)`,`ftsAvailable: ${e.ftsAvailable?"yes":"no"}`,`vectorEnabled: ${e.vectorEnabled?"yes":"no"}`,`healthy: ${e.healthy?"yes":"no"}`,"","factsByCategory:",...Object.entries(e.factsByCategory).map(([d,t])=>` - ${d}: ${t}`),"","meta:",...Object.entries(e.meta).map(([d,t])=>` - ${d}: ${t}`)];if(e.integrityStats&&Object.keys(e.integrityStats).length>0){r.push("","DB stats:");let d=Math.max(...Object.keys(e.integrityStats).map(t=>t.length));for(let[t,a]of Object.entries(e.integrityStats))r.push(` - ${t.padEnd(d)} ${a}`);}r.push("",I("status",o));let c=r.join(`
44
+ `);return n.sync?w(c,{}).content:(await $(c,{toolName:o,writeToDisk:n.writeToDisk})).content}async function P(e,n={}){let o=n.toolName??"memory_consolidate",r=["**`memory_consolidate:result`**","",`total facts scanned: ${e.totalFacts}`,`deduped (merged): ${e.dedupedCount}`,`compressed: ${e.compressedCount}`,`archived to archive/: ${e.archivedCount}`,`skipped (no change): ${e.skippedCount}`,`duration: ${e.durationMs}ms`,"",I("consolidate",o)].join(`
45
+ `);return n.sync?w(r,{}).content:(await $(r,{toolName:o,writeToDisk:n.writeToDisk})).content}var v=20;async function j(e,n={}){let o=n.toolName??"memory_sync",r=[`**\`memory_sync:${e.dryRun?"DRY_RUN":"OK"}\`**`,"",`windowDays: ${e.windowDays} (threshold: ${e.archiveThreshold})`,"","## Stage A (db \u2192 .md)",`- generated: ${e.generatedCount}`,`- skipped (idempotent): ${e.skippedCount}`,`- failed (best-effort): ${e.failedGenerateCount}`,"","## Stage B (active/ \u2192 archive/)",`- ${e.dryRun?"would archive":"archived"}: ${e.archivedCount}`];if(e.archivedRecords.length>0){r.push("","### Archived records:");let d=e.archivedRecords.slice(0,v);for(let t of d)r.push(`- ${t.firstFactId} (${t.firstCreatedAt})`),r.push(` - source: \`${t.source}\``),r.push(` - target: \`${t.target}\``);e.archivedRecords.length>v&&r.push(`... and ${e.archivedRecords.length-v} more (use --json for full list)`);}r.push("",`duration: ${e.durationMs}ms`,"",I("sync",o));let c=r.join(`
46
+ `);return n.sync?w(c,{}).content:(await $(c,{toolName:o,writeToDisk:n.writeToDisk})).content}async function L(e,n={}){let o=n.toolName??"memory_doctor",s=`**\`memory_doctor:${e.healthy?"OK":"ISSUES"}\`**`,r=t=>t?"\u2705":"\u274C",c=e.checks.map(t=>`${r(t.passed)} ${t.name}: ${t.message}`).join(`
47
47
  `),d=[s,"",c,"",I("doctor",o)].join(`
48
- `);return n.sync?w(d,{}).content:(await $(d,{toolName:o,writeToDisk:n.writeToDisk})).content}async function R(e,n,o={}){let s=n,r=typeof s.kind=="string";switch((r?s:{kind:e}).kind){case "recall":{let d=r?{hits:s.hits,total:s.totalCount??s.total??0,truncated:s.truncated??false}:n;return v(d,{...o,query:s.query??o.query??"",agentId:s.agentId??o.agentId??"",scope:s.scope??o.scope??"agent_only"})}case "remember":{let d=r?{fact:s.fact,nodeIds:s.nodeIds}:n;return A(d,o)}case "forget":return _(r?s:n,o);case "graph_query":return N(r?s:n,o);case "status":return M(r?s:n,o);case "consolidate":return O(r?s:n,o);case "sync":return P(r?s:n,o);case "doctor":return j(r?s:n,o);default:throw new Error(`renderOperationMarkdown: unsupported op "${e}"`)}}var D=Log.create({service:"memory-mcp-stdio"});function Re(e){let n=new Map,o=e.isRemote??true,s=!o;function r(t){let a=Locale.resolveLocaleLang();return {agentId:t.agentId??e.agentId,isTrustedLocal:t.isTrustedLocal??s,remote:o,locale:a,dbPath:e.dbPath,workspaceDir:e.workspaceDir,rootDir:e.workspaceDir,config:A$1({agentId:e.agentId,dbPath:e.dbPath})}}function c(t,a){return {content:[{type:"text",text:t}],isError:a}}function d(t){return formatFailClosed(t,s)}return n.set("recall",async t=>{try{let a=t,m=r({agentId:a.agentId}),u=await z("recall",t,m);return {content:[{type:"text",text:await R("recall",u,{toolName:"memory_recall",query:a.query,agentId:a.agentId??e.agentId,scope:a.scope??"agent_only"})}]}}catch(a){return c(d(a),true)}}),n.set("remember",async t=>{try{let m=r({agentId:t.agentId}),u=await z("remember",t,m);return {content:[{type:"text",text:await R("remember",u,{toolName:"memory_remember"})}]}}catch(a){return c(d(a),true)}}),n.set("update",async t=>{try{let m=r({agentId:t.agentId}),u=await z("update",t,m),l=u.fieldsUpdated.length>0?u.fieldsUpdated.join(", "):"(no-op)",i=u.contentChanged?" (embedding rewritten)":"";return {content:[{type:"text",text:`Memory updated.
48
+ `);return n.sync?w(d,{}).content:(await $(d,{toolName:o,writeToDisk:n.writeToDisk})).content}async function R(e,n,o={}){let s=n,r=typeof s.kind=="string";switch((r?s:{kind:e}).kind){case "recall":{let d=r?{hits:s.hits,total:s.totalCount??s.total??0,truncated:s.truncated??false}:n;return M(d,{...o,query:s.query??o.query??"",agentId:s.agentId??o.agentId??"",scope:s.scope??o.scope??"agent_only"})}case "remember":{let d=r?{fact:s.fact,nodeIds:s.nodeIds}:n;return A(d,o)}case "forget":return _(r?s:n,o);case "graph_query":return N(r?s:n,o);case "status":return O(r?s:n,o);case "consolidate":return P(r?s:n,o);case "sync":return j(r?s:n,o);case "doctor":return L(r?s:n,o);default:throw new a.UnsupportedOperationError({message:`renderOperationMarkdown: unsupported op "${e}"`,opName:e,renderer:"markdown"})}}var k=Log.create({service:"memory-mcp-stdio"});function Ee(e){let n=new Map,o=e.isRemote??true,s=!o;function r(t){let a=Locale.resolveLocaleLang();return {agentId:t.agentId??e.agentId,isTrustedLocal:t.isTrustedLocal??s,remote:o,locale:a,dbPath:e.dbPath,workspaceDir:e.workspaceDir,rootDir:e.workspaceDir,config:A$1({agentId:e.agentId,dbPath:e.dbPath})}}function c(t,a){return {content:[{type:"text",text:t}],isError:a}}function d(t){return formatFailClosed(t,s)}return n.set("recall",async t=>{try{let a=t,m=r({agentId:a.agentId}),u=await z("recall",t,m);return {content:[{type:"text",text:await R("recall",u,{toolName:"memory_recall",query:a.query,agentId:a.agentId??e.agentId,scope:a.scope??"agent_only"})}]}}catch(a){return c(d(a),true)}}),n.set("remember",async t=>{try{let m=r({agentId:t.agentId}),u=await z("remember",t,m);return {content:[{type:"text",text:await R("remember",u,{toolName:"memory_remember"})}]}}catch(a){return c(d(a),true)}}),n.set("update",async t=>{try{let m=r({agentId:t.agentId}),u=await z("update",t,m),l=u.fieldsUpdated.length>0?u.fieldsUpdated.join(", "):"(no-op)",i=u.contentChanged?" (embedding rewritten)":"";return {content:[{type:"text",text:`Memory updated.
49
49
  id: ${u.fact.id}
50
50
  category: ${u.fact.category}
51
51
  importance: ${u.fact.importance}
@@ -56,9 +56,9 @@ sessionId: ${t.sessionId??"(unknown)"}
56
56
  extractedCount: ${l.extractedCount}
57
57
  factIds: ${l.factIds.length>0?l.factIds.join(", "):"(none)"}
58
58
  messageRange: ${l.messageRange.fromMessageId} -> ${l.messageRange.toMessageId}
59
- `}]}}catch(a){return c(d(a),true)}}),n.set("consolidate",async t=>{try{let m=r({agentId:t.agentId,isTrustedLocal:!0}),u=await z("consolidate",t,m);return {content:[{type:"text",text:await R("consolidate",u,{toolName:"memory_consolidate"})}]}}catch(a){return c(d(a),true)}}),n.set("sync",async t=>{try{let m=t.agentId?.trim();if(!m)return c(d(new Error("memory_sync: agentId is required (sync requires agentId, see ADR 0069)")),!0);let u=r({agentId:m,isTrustedLocal:!0}),l=await z("sync",t,u);return {content:[{type:"text",text:await R("sync",l,{toolName:"memory_sync"})}]}}catch(a){return c(d(a),true)}}),n.set("graph_query",async t=>{try{let a=t,m=r({agentId:a.agentId}),u=await z("graph_query",t,m);return {content:[{type:"text",text:await R("graph_query",u,{toolName:"memory_graph_query",scope:a.scope??"agent_only"})}]}}catch(a){return c(d(a),true)}}),n.set("status",async t=>{try{let m=r({agentId:(t??{}).agentId}),u=await z("status",t,m),{renderKnowledgeStatus:l}=await import('@easbot/terminal'),i=u;return {content:[{type:"text",text:l({packageName:"memory",rootDir:i.workspaceDir??"",configPath:i.configPath??"",configExists:typeof i.configExists=="boolean"?i.configExists:!0,dbPath:i.dbPath??"",dbExists:typeof i.dbExists=="boolean"?i.dbExists:!0,dbSize:typeof i.dbSize=="number"?i.dbSize:void 0,indexState:i.indexState,schemaVersion:typeof i.schemaVersion=="number"?i.schemaVersion:void 0,extractionVersion:typeof i.extractionVersion=="number"?i.extractionVersion:void 0,lastSyncAt:i.lastSyncAt,vectorEnabled:typeof i.vectorEnabled=="boolean"?i.vectorEnabled:!1,embeddingDims:typeof i.embeddingDims=="number"?i.embeddingDims:void 0,llm:i.llm??{initialized:!1,capabilities:{}},backend:i.backend,healthy:typeof i.healthy=="boolean"?i.healthy:!0,recommendation:i.recommendation,dbStats:(()=>{let h=i.dbStats;if(h&&typeof h=="object"&&Object.keys(h).length>0)return {...h};let f=i.integrityStats;if(f&&typeof f=="object"&&Object.keys(f).length>0)return {...f}})(),extras:(()=>{let h={};if(typeof i.agentId=="string"&&(h.agent_id=i.agentId),typeof i.ftsAvailable=="boolean"&&(h.fts_available=i.ftsAvailable?"yes":"no"),i.factsByCategory&&typeof i.factsByCategory=="object")for(let[f,b]of Object.entries(i.factsByCategory))typeof b=="number"&&b>0&&(h[`facts/${f}`]=b);if(i.meta&&typeof i.meta=="object")for(let[f,b]of Object.entries(i.meta))b!==void 0&&(h[`meta/${f}`]=b);return Object.keys(h).length>0?h:void 0})()})}]}}catch(a){return c(d(a),true)}}),n.set("doctor",async t=>{try{let m=r({agentId:(t??{}).agentId,isTrustedLocal:!0}),u=await z("doctor",t,m);return {content:[{type:"text",text:await R("doctor",u,{toolName:"memory_doctor"})}]}}catch(a){return c(d(a),true)}}),n.set("init",async t=>{try{let a=r({isTrustedLocal:!0}),u=await z("init",t,a);return {content:[{type:"text",text:`Init complete.
59
+ `}]}}catch(a){return c(d(a),true)}}),n.set("consolidate",async t=>{try{let m=r({agentId:t.agentId,isTrustedLocal:!0}),u=await z("consolidate",t,m);return {content:[{type:"text",text:await R("consolidate",u,{toolName:"memory_consolidate"})}]}}catch(a){return c(d(a),true)}}),n.set("sync",async t=>{try{let m=t.agentId?.trim();if(!m)return c(d(new Error("memory_sync: agentId is required (sync requires agentId, see ADR 0069)")),!0);let u=r({agentId:m,isTrustedLocal:!0}),l=await z("sync",t,u);return {content:[{type:"text",text:await R("sync",l,{toolName:"memory_sync"})}]}}catch(a){return c(d(a),true)}}),n.set("graph_query",async t=>{try{let a=t,m=r({agentId:a.agentId}),u=await z("graph_query",t,m);return {content:[{type:"text",text:await R("graph_query",u,{toolName:"memory_graph_query",scope:a.scope??"agent_only"})}]}}catch(a){return c(d(a),true)}}),n.set("status",async t=>{try{let m=r({agentId:(t??{}).agentId}),u=await z("status",t,m),{renderKnowledgeStatus:l}=await import('@easbot/terminal'),i=u;return {content:[{type:"text",text:l({packageName:"memory",rootDir:i.workspaceDir??"",configPath:i.configPath??"",configExists:typeof i.configExists=="boolean"?i.configExists:!0,dbPath:i.dbPath??"",dbExists:typeof i.dbExists=="boolean"?i.dbExists:!0,dbSize:typeof i.dbSize=="number"?i.dbSize:void 0,indexState:i.indexState,schemaVersion:typeof i.schemaVersion=="number"?i.schemaVersion:void 0,extractionVersion:typeof i.extractionVersion=="number"?i.extractionVersion:void 0,lastSyncAt:i.lastSyncAt,vectorEnabled:typeof i.vectorEnabled=="boolean"?i.vectorEnabled:!1,embeddingDims:typeof i.embeddingDims=="number"?i.embeddingDims:void 0,llm:i.llm??{initialized:!1,capabilities:{}},backend:i.backend,healthy:typeof i.healthy=="boolean"?i.healthy:!0,recommendation:i.recommendation,dbStats:(()=>{let p=i.dbStats;if(p&&typeof p=="object"&&Object.keys(p).length>0)return {...p};let g=i.integrityStats;if(g&&typeof g=="object"&&Object.keys(g).length>0)return {...g}})(),extras:(()=>{let p={};if(typeof i.agentId=="string"&&(p.agent_id=i.agentId),typeof i.ftsAvailable=="boolean"&&(p.fts_available=i.ftsAvailable?"yes":"no"),i.factsByCategory&&typeof i.factsByCategory=="object")for(let[g,b]of Object.entries(i.factsByCategory))typeof b=="number"&&b>0&&(p[`facts/${g}`]=b);if(i.meta&&typeof i.meta=="object")for(let[g,b]of Object.entries(i.meta))b!==void 0&&(p[`meta/${g}`]=b);return Object.keys(p).length>0?p:void 0})()})}]}}catch(a){return c(d(a),true)}}),n.set("doctor",async t=>{try{let m=r({agentId:(t??{}).agentId,isTrustedLocal:!0}),u=await z("doctor",t,m);return {content:[{type:"text",text:await R("doctor",u,{toolName:"memory_doctor"})}]}}catch(a){return c(d(a),true)}}),n.set("init",async t=>{try{let a=r({isTrustedLocal:!0}),u=await z("init",t,a);return {content:[{type:"text",text:`Init complete.
60
60
  dbPath: ${u.dbPath}
61
61
  tablesCreated: ${u.tablesCreated}
62
62
  migrationsApplied: ${u.migrationsApplied}
63
63
  durationMs: ${u.durationMs}
64
- `}]}}catch(a){return c(d(a),true)}}),n}var Ce={recall:c,remember:d,update:e,forget:f,extract:g,consolidate:h,sync:m,graph_query:i,status:j$1,doctor:k$1,init:l};function Te(e,n){let o=x[e],s={title:o?.annotations?.defaultDescription??e,readOnlyHint:o?.annotations?.readOnlyHint??false,destructiveHint:o?.annotations?.destructiveHint??false,idempotentHint:o?.annotations?.idempotentHint??true,openWorldHint:false},r=Ce[e];return {name:e,description:o?.annotations?.defaultDescription??`memory op: ${e}`,inputSchema:r??{type:"object",properties:{},required:[],additionalProperties:false},annotations:s,handler:n}}var re;(o=>{async function e(s,r){let{getMemoryDbPath:c,getInstance:d}=await import('./interfaces-LPJU4KS3.mjs'),a=r!==null&&typeof r=="object"&&"agentId"in r&&"dbPath"in r?r:{agentId:process.env.EASBOT_AGENT_ID??"default",dbPath:c(),workspaceDir:d().worktree,isRemote:false};extendKnownErrorCodes(["AGENT_ID_REQUIRED","SESSION_ID_REQUIRED","CATEGORY_REQUIRED","IMPORTANCE_REQUIRED","TIMERANGE_REQUIRED","DRY_RUN_NO_DELETE"]);let m=new ToolRegistry,u=Re(a),l=Object.keys(x);for(let g of l){let C=u.get(g);if(!C)throw new Error(`MemoryStdioServer.start: missing handler for tool "${g}"`);m.register(Te(g,C));}D.info("starting memory MCP stdio server",{id:s.id,name:s.name,toolCount:l.length,isRemote:a.isRemote??true});let i=await createAndStartStdioServer(s,m),p=null,h=new Promise(g=>{p=g;}),f=g=>{D.info("received signal, stopping MCP server",{signal:g}),p?.();},b=()=>f("SIGINT"),S=()=>f("SIGTERM"),L=(g,C)=>process.listeners(g).includes(C);L("SIGINT",b)||process.on("SIGINT",b),L("SIGTERM",S)||process.on("SIGTERM",S);try{await h;}finally{try{process.off("SIGINT",b),process.off("SIGTERM",S);}catch(g){D.warn("failed to remove signal handlers",{error:g instanceof Error?g.message:String(g)});}try{await i.stop();}catch(g){D.warn("server.stop failed during cleanup",{error:g instanceof Error?g.message:String(g)});}}return {id:s.id,name:s.name,version:s.version,tools:l}}o.start=e;function n(){return Object.keys(x)}o.getToolNames=n;})(re||(re={}));export{R as a,re as b};
64
+ `}]}}catch(a){return c(d(a),true)}}),n}var xe={recall:c,remember:d,update:e,forget:f,extract:g,consolidate:h,sync:m,graph_query:i,status:j$1,doctor:k$1,init:l};function De(e,n){let o=x[e],s={title:o?.annotations?.defaultDescription??e,readOnlyHint:o?.annotations?.readOnlyHint??false,destructiveHint:o?.annotations?.destructiveHint??false,idempotentHint:o?.annotations?.idempotentHint??true,openWorldHint:false},r=xe[e];return {name:e,description:o?.annotations?.defaultDescription??`memory op: ${e}`,inputSchema:r??{type:"object",properties:{},required:[],additionalProperties:false},annotations:s,handler:n}}var ae;(o=>{async function e(s,r){let{getMemoryDbPath:c,getInstance:d}=await import('./interfaces-7TJ645HL.mjs'),a$1=r!==null&&typeof r=="object"&&"agentId"in r&&"dbPath"in r?r:{agentId:process.env.EASBOT_AGENT_ID??"default",dbPath:c(d().worktree),workspaceDir:d().worktree,isRemote:false};extendKnownErrorCodes(["AGENT_ID_REQUIRED","SESSION_ID_REQUIRED","CATEGORY_REQUIRED","IMPORTANCE_REQUIRED","TIMERANGE_REQUIRED","DRY_RUN_NO_DELETE"]);let m=new ToolRegistry,u=Ee(a$1),l=Object.keys(x);for(let y of l){let C=u.get(y);if(!C)throw new a.MissingMcpHandlerError({message:`MemoryStdioServer.start: missing handler for tool "${y}"`,toolName:y});m.register(De(y,C));}k.info("starting memory MCP stdio server",{id:s.id,name:s.name,toolCount:l.length,isRemote:a$1.isRemote??true});let i=await createAndStartStdioServer(s,m),f=null,p=new Promise(y=>{f=y;}),g=y=>{k.info("received signal, stopping MCP server",{signal:y}),f?.();},b=()=>g("SIGINT"),S=()=>g("SIGTERM"),F=(y,C)=>process.listeners(y).includes(C);F("SIGINT",b)||process.on("SIGINT",b),F("SIGTERM",S)||process.on("SIGTERM",S);try{await p;}finally{try{process.off("SIGINT",b),process.off("SIGTERM",S);}catch(y){k.warn("failed to remove signal handlers",{error:errorMeta(y)});}try{await i.stop();}catch(y){k.warn("server.stop failed during cleanup",{error:errorMeta(y)});}}return {id:s.id,name:s.name,version:s.version,tools:l}}o.start=e;function n(){return Object.keys(x)}o.getToolNames=n;})(ae||(ae={}));export{R as a,ae as b};