@easbot/memory 0.3.36 → 0.3.37
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.
- package/README.en.md +116 -1
- package/README.md +68 -15
- package/dist/index.cjs +27 -7
- package/dist/index.d.cts +86 -5
- package/dist/index.d.ts +86 -5
- package/dist/index.mjs +27 -7
- package/package.json +12 -10
- package/dist/assets/txt/src/plugin/tool/description.txt +0 -12
package/README.en.md
CHANGED
|
@@ -6,7 +6,7 @@ Long-term memory library for the EASBOT ecosystem, providing per-agent fact stor
|
|
|
6
6
|
|
|
7
7
|
## Version
|
|
8
8
|
|
|
9
|
-
v0.3.
|
|
9
|
+
v0.3.37
|
|
10
10
|
## Features (v0.4.0)
|
|
11
11
|
|
|
12
12
|
- **9 op unified entry** — `recall / remember / forget / extract / consolidate / graph_query / status / doctor / init`; MCP / CLI / Agent Tool share the same `executeOp(name, args, ctx)`.
|
|
@@ -187,6 +187,115 @@ import type {
|
|
|
187
187
|
} from '@easbot/memory/hooks';
|
|
188
188
|
```
|
|
189
189
|
|
|
190
|
+
### plugin (plugin / hook / tool)
|
|
191
|
+
|
|
192
|
+
`@easbot/memory` ships an installable plugin following the `@easbot/plugin` contract:
|
|
193
|
+
3 lifecycle hooks and 1 `memory` tool. The implementation lives in `src/plugin/`, and
|
|
194
|
+
every symbol is **imported from the package root** (no subpath exports).
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
import {
|
|
198
|
+
MemoryPlugin,
|
|
199
|
+
MEMORY_PLUGIN_MANIFEST,
|
|
200
|
+
MEMORY_HOOK_EVENTS,
|
|
201
|
+
MemoryPluginHook,
|
|
202
|
+
createMemoryHookMatchers,
|
|
203
|
+
MemoryTool,
|
|
204
|
+
} from '@easbot/memory';
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
| Export | Description |
|
|
208
|
+
| ------------------------------------- | ------------------------------------------------------------------------------------------- |
|
|
209
|
+
| `MemoryPlugin` / `default` / `Plugin` | Plugin entry, returns `Promise<PluginDefinition>` |
|
|
210
|
+
| `MEMORY_PLUGIN_MANIFEST` | Manifest mirroring `plugin.json` (`name` / `version` / `entry` / `capabilities`) |
|
|
211
|
+
| `MEMORY_HOOK_EVENTS` | 3 dotted events: `context.build.before` / `session.compacting` / `tool.failure` |
|
|
212
|
+
| `MemoryPluginHook` | `HookInfo` shape (host built-in registration path) |
|
|
213
|
+
| `createMemoryHookMatchers()` | `HookMatcher[]` shape (plugin registration path) |
|
|
214
|
+
| `MemoryTool` | `ToolDefinition`: flat `args` map (`operation` + per-op params), `execute` returns a string |
|
|
215
|
+
| `MEMORY_TOOL_OPS` | 7 ops: `recall` / `remember` / `update` / `forget` / `extract` / `graph_query` / `status` |
|
|
216
|
+
| `MEMORY_TOOL_ARGS` | Flat parameter schema, field-by-field aligned with the host built-in memory tool |
|
|
217
|
+
|
|
218
|
+
#### Tool parameter contract (aligned with the host built-in tool)
|
|
219
|
+
|
|
220
|
+
The plugin tool `args` match the host built-in `packages/agent/src/tool/memory.ts`
|
|
221
|
+
field by field: `operation` selects the op, and the remaining flat parameters are
|
|
222
|
+
shared across ops (the host `packages/agent/src/plugin/plugin.ts` enforces
|
|
223
|
+
`z.object(args)`, so a discriminated union is not available).
|
|
224
|
+
|
|
225
|
+
| Op | Effective parameters |
|
|
226
|
+
| ------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
|
|
227
|
+
| `recall` | `query` (required) / `limit` (default 10, max 100) / `category` / `minImportance` / `maxEdgesPerNode` / `includeGraph` / `includeShared` |
|
|
228
|
+
| `remember` | `content` (required) / `category` / `importance` (1-10) / `tags` |
|
|
229
|
+
| `update` | `factId` (required) plus at least one of `content` / `category` / `importance` / `tags` |
|
|
230
|
+
| `forget` | `factId` (required) / `dryRun` / `force` |
|
|
231
|
+
| `extract` | `lastN` (default 10) / `fromMessageId` |
|
|
232
|
+
| `graph_query` | `query` or `nodeId` (one required) / `maxDepth` (default 2, max 5) / `maxNodes` (default 100, max 500) / `maxEdgesPerNode` |
|
|
233
|
+
| `status` | no extra parameters |
|
|
234
|
+
|
|
235
|
+
Op-specific required fields, ranges and mutual exclusions are validated a second
|
|
236
|
+
time inside the plugin (`parseOperationParams`); validation failures return a
|
|
237
|
+
structured error instead of throwing.
|
|
238
|
+
|
|
239
|
+
#### Distribution artifact generation
|
|
240
|
+
|
|
241
|
+
The distribution artifacts under `plugins/memory/` (`plugin.json` / `package.json` /
|
|
242
|
+
`index.mjs`) and this plugin's entry in `plugins/.easbot-plugin/marketplace.json`
|
|
243
|
+
**MUST be generated by the script, MUST NOT be edited by hand**:
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
# Generate / refresh the distribution artifacts
|
|
247
|
+
pnpm plugin:generate
|
|
248
|
+
|
|
249
|
+
# Verify the artifacts are up to date (CI guard, exits 1 when stale)
|
|
250
|
+
pnpm plugin:check
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
Data sources and outputs of `scripts/generate-plugin-distribution.ts`:
|
|
254
|
+
|
|
255
|
+
| Input | Output |
|
|
256
|
+
| ---------------------------------------------------- | ---------------------------------------------------------- |
|
|
257
|
+
| `version` in `package.json` | version fields in `plugin.json` / `package.json` |
|
|
258
|
+
| `MEMORY_PLUGIN_MANIFEST` in `src/plugin/manifest.ts` | name / description / entry / capabilities in `plugin.json` |
|
|
259
|
+
| allow-listed exports in `src/plugin/index.ts` | re-export identifier in `index.mjs` |
|
|
260
|
+
| `hook/` and `tool/` directories under `src/plugin/` | capabilities validation (exits 1 when undeclared) |
|
|
261
|
+
|
|
262
|
+
The package version is the single source of truth: when
|
|
263
|
+
`MEMORY_PLUGIN_VERSION` in `src/plugin/manifest.ts` diverges, the script syncs it
|
|
264
|
+
to the package version (in `--check` mode it only reports the divergence).
|
|
265
|
+
The script is idempotent — nothing is written when the artifacts already match.
|
|
266
|
+
|
|
267
|
+
#### Installation and runtime loading
|
|
268
|
+
|
|
269
|
+
The distribution directory lives in the repository-root distribution area
|
|
270
|
+
`plugins/memory/` (`{plugin.json,package.json,index.mjs}`); the marketplace
|
|
271
|
+
manifest is the single repo-wide one at `plugins/.easbot-plugin/marketplace.json`.
|
|
272
|
+
`index.mjs` only re-exports the package root, therefore you MUST build
|
|
273
|
+
`@easbot/memory` before using it.
|
|
274
|
+
|
|
275
|
+
```bash
|
|
276
|
+
pnpm --filter @easbot/memory build
|
|
277
|
+
|
|
278
|
+
# Register the local marketplace (path is the repository-root distribution area)
|
|
279
|
+
easbot plugins marketplace add ./plugins
|
|
280
|
+
|
|
281
|
+
# Install the memory plugin (non-interactive requires an explicit scope)
|
|
282
|
+
easbot plugins install -m plugins -p memory --project -y --json
|
|
283
|
+
|
|
284
|
+
# Inspect runtime registration: hooks=4 / tools=1
|
|
285
|
+
easbot plugins list --json
|
|
286
|
+
easbot plugins info memory --json
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
`install` copies `memory/` into `<scope>/plugins/memory/` and writes
|
|
290
|
+
`marketplace:<marketId>|memory` into `config.plugin`; at runtime the specifier is
|
|
291
|
+
resolved to the installed `plugin.json.entry`, then imported and registered
|
|
292
|
+
(hooks + tool). `disable memory` removes the config entry so the plugin is no
|
|
293
|
+
longer loaded, `enable memory` appends it back.
|
|
294
|
+
|
|
295
|
+
> Constraints: only `.mjs` / `.js` / `.cjs` artifacts are loaded — never `.ts`
|
|
296
|
+
> sources; no network access and no cloning. `plugin.json.entry` must start with
|
|
297
|
+
> `./` and must not contain `..` segments.
|
|
298
|
+
|
|
190
299
|
## CLI / MCP dual entry (v0.4 stage 4)
|
|
191
300
|
|
|
192
301
|
### Standalone CLI (`easbot-memory`)
|
|
@@ -474,6 +583,12 @@ pnpm type-check
|
|
|
474
583
|
|
|
475
584
|
# Lint (biome 2.x)
|
|
476
585
|
pnpm biome-lint
|
|
586
|
+
|
|
587
|
+
# Generate the plugin distribution artifacts (plugins/memory + marketplace manifest)
|
|
588
|
+
pnpm plugin:generate
|
|
589
|
+
|
|
590
|
+
# Verify the plugin distribution artifacts are up to date
|
|
591
|
+
pnpm plugin:check
|
|
477
592
|
```
|
|
478
593
|
|
|
479
594
|
## License
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ EASBOT 生态系统的长期记忆管理库(v0.4.0)。提供分层记忆、K
|
|
|
6
6
|
|
|
7
7
|
## 版本
|
|
8
8
|
|
|
9
|
-
v0.3.
|
|
9
|
+
v0.3.37
|
|
10
10
|
## 特性(v0.4.0)
|
|
11
11
|
|
|
12
12
|
- **10 op 统一入口**(ADR 0069 +1 sync):`recall / remember / forget / extract / consolidate / sync / graph_query / status / doctor / init`,MCP / CLI / Agent Tool 三端共享。
|
|
@@ -216,29 +216,76 @@ import {
|
|
|
216
216
|
} from '@easbot/memory';
|
|
217
217
|
```
|
|
218
218
|
|
|
219
|
-
| 导出 | 说明
|
|
220
|
-
| ------------------------------------- |
|
|
221
|
-
| `MemoryPlugin` / `default` / `Plugin` | 插件入口,返回 `Promise<PluginDefinition>`
|
|
222
|
-
| `MEMORY_PLUGIN_MANIFEST` | `plugin.json` 对应的清单(`name` / `version` / `entry` / `capabilities`)
|
|
223
|
-
| `MEMORY_HOOK_EVENTS` | 3 个点分事件:`context.build.before` / `session.compacting` / `tool.failure`
|
|
224
|
-
| `MemoryPluginHook` | `HookInfo` 形态(宿主内置注册路径)
|
|
225
|
-
| `createMemoryHookMatchers()` | `HookMatcher[]` 形态(插件注册路径)
|
|
226
|
-
| `MemoryTool` | `ToolDefinition`:`args
|
|
219
|
+
| 导出 | 说明 |
|
|
220
|
+
| ------------------------------------- | ------------------------------------------------------------------------------------------- |
|
|
221
|
+
| `MemoryPlugin` / `default` / `Plugin` | 插件入口,返回 `Promise<PluginDefinition>` |
|
|
222
|
+
| `MEMORY_PLUGIN_MANIFEST` | `plugin.json` 对应的清单(`name` / `version` / `entry` / `capabilities`) |
|
|
223
|
+
| `MEMORY_HOOK_EVENTS` | 3 个点分事件:`context.build.before` / `session.compacting` / `tool.failure` |
|
|
224
|
+
| `MemoryPluginHook` | `HookInfo` 形态(宿主内置注册路径) |
|
|
225
|
+
| `createMemoryHookMatchers()` | `HookMatcher[]` 形态(插件注册路径) |
|
|
226
|
+
| `MemoryTool` | `ToolDefinition`:`args` 为扁平 map(`operation` + 各 op 参数),`execute` 返回字符串 |
|
|
227
|
+
| `MEMORY_TOOL_OPS` | 7 个 op:`recall` / `remember` / `update` / `forget` / `extract` / `graph_query` / `status` |
|
|
228
|
+
| `MEMORY_TOOL_ARGS` | 扁平参数 schema(与宿主内置 memory 工具逐字段对齐) |
|
|
229
|
+
|
|
230
|
+
#### 工具参数契约(对齐宿主内置工具)
|
|
231
|
+
|
|
232
|
+
插件工具的 `args` 与宿主内置 `packages/agent/src/tool/memory.ts` **逐字段一致**:
|
|
233
|
+
`operation` 决定本次调用的 op,其余参数按 op 语义共享(扁平 map,宿主
|
|
234
|
+
`packages/agent/src/plugin/plugin.ts` 会强制 `z.object(args)`,不支持判别联合)。
|
|
235
|
+
|
|
236
|
+
| op | 生效参数 |
|
|
237
|
+
| ------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
|
|
238
|
+
| `recall` | `query`(必填)/ `limit`(默认 10,上限 100)/ `category` / `minImportance` / `maxEdgesPerNode` / `includeGraph` / `includeShared` |
|
|
239
|
+
| `remember` | `content`(必填)/ `category` / `importance`(1-10)/ `tags` |
|
|
240
|
+
| `update` | `factId`(必填)+ `content` / `category` / `importance` / `tags`(至少一项) |
|
|
241
|
+
| `forget` | `factId`(必填)/ `dryRun` / `force` |
|
|
242
|
+
| `extract` | `lastN`(默认 10)/ `fromMessageId` |
|
|
243
|
+
| `graph_query` | `query` 或 `nodeId`(二者其一必填)/ `maxDepth`(默认 2,上限 5)/ `maxNodes`(默认 100,上限 500)/ `maxEdgesPerNode` |
|
|
244
|
+
| `status` | 无额外参数 |
|
|
245
|
+
|
|
246
|
+
op 专属的必填 / 取值范围 / 互斥约束由插件侧做**二次校验**(`parseOperationParams`),
|
|
247
|
+
校验失败返回结构化错误而非抛异常。
|
|
248
|
+
|
|
249
|
+
#### 分发产物自动生成
|
|
250
|
+
|
|
251
|
+
`plugins/memory/` 下的分发产物(`plugin.json` / `package.json` / `index.mjs`)与
|
|
252
|
+
`plugins/.easbot-plugin/marketplace.json` 中的本插件条目 **MUST 由脚本生成,MUST NOT 手改**:
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
# 生成 / 更新分发产物
|
|
256
|
+
pnpm plugin:generate
|
|
257
|
+
|
|
258
|
+
# 只校验产物是否最新(CI 用,过期则 exit 1)
|
|
259
|
+
pnpm plugin:check
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
脚本 `scripts/generate-plugin-distribution.ts` 的数据来源与产物:
|
|
263
|
+
|
|
264
|
+
| 输入 | 产物 |
|
|
265
|
+
| ---------------------------------------------------- | ---------------------------------------------------------- |
|
|
266
|
+
| `package.json` 的 `version` | `plugin.json` / `package.json` 的版本 |
|
|
267
|
+
| `src/plugin/manifest.ts` 的 `MEMORY_PLUGIN_MANIFEST` | `plugin.json` 的 name / description / entry / capabilities |
|
|
268
|
+
| `src/plugin/index.ts` 的白名单导出 | `index.mjs` 的 re-export 标识符 |
|
|
269
|
+
| `src/plugin/` 下的 `hook/` `tool/` 目录 | capabilities 能力校验(缺声明即报错退出) |
|
|
270
|
+
|
|
271
|
+
版本真值源是 `package.json`;`src/plugin/manifest.ts` 的 `MEMORY_PLUGIN_VERSION`
|
|
272
|
+
与之不一致时脚本会自动同步(`--check` 模式只报错不改文件)。
|
|
273
|
+
脚本幂等:产物内容与磁盘一致时不写盘。
|
|
227
274
|
|
|
228
275
|
#### 安装与运行时加载
|
|
229
276
|
|
|
230
|
-
|
|
231
|
-
`
|
|
232
|
-
|
|
277
|
+
分发目录位于仓根统一分发区 `plugins/memory/`(`{plugin.json,package.json,index.mjs}`),
|
|
278
|
+
marketplace 清单为仓内唯一一份 `plugins/.easbot-plugin/marketplace.json`。
|
|
279
|
+
`index.mjs` 只做包根 re-export,因此使用前 MUST 先构建 `@easbot/memory`。
|
|
233
280
|
|
|
234
281
|
```bash
|
|
235
282
|
pnpm --filter @easbot/memory build
|
|
236
283
|
|
|
237
|
-
# 注册本地 marketplace
|
|
238
|
-
easbot plugins marketplace add ./
|
|
284
|
+
# 注册本地 marketplace(路径为仓根统一分发区)
|
|
285
|
+
easbot plugins marketplace add ./plugins
|
|
239
286
|
|
|
240
287
|
# 安装 memory 插件(非交互必须显式给出 scope)
|
|
241
|
-
easbot plugins install -m
|
|
288
|
+
easbot plugins install -m plugins -p memory --project -y --json
|
|
242
289
|
|
|
243
290
|
# 查看运行时注册结果:hooks=4 / tools=1
|
|
244
291
|
easbot plugins list --json
|
|
@@ -542,6 +589,12 @@ pnpm type-check
|
|
|
542
589
|
|
|
543
590
|
# lint(biome 2.x)
|
|
544
591
|
pnpm biome-lint
|
|
592
|
+
|
|
593
|
+
# 生成插件分发产物(plugins/memory + marketplace 清单)
|
|
594
|
+
pnpm plugin:generate
|
|
595
|
+
|
|
596
|
+
# 校验插件分发产物是否最新
|
|
597
|
+
pnpm plugin:check
|
|
545
598
|
```
|
|
546
599
|
|
|
547
600
|
## 许可证
|
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
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'),
|
|
2
|
-
${
|
|
3
|
-
`)}`,
|
|
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}
|
|
4
4
|
|
|
5
|
-
${
|
|
6
|
-
${
|
|
7
|
-
`)}`;return
|
|
8
|
-
`);try{let n=await chunkQAEIHJOF_cjs.z("remember",{content:s,category:"error_pattern",importance:6,tags:["post-tool-failure",`tool:${t.toolName}`,`err:${c}`],sessionId:t.sessionId,msgId:typeof t.extras.msgId=="string"?t.extras.msgId:void 0},M(t.agentId));return a(e,{hook:r,ok:!0,logLine:`tool failure: wrote error_pattern fact ${n.fact.id} (tool=${t.toolName}, errHash=${c})`})}catch(n){let m=utils.errorMeta(n);return eo.warn("memory tool failure hook failed",{error:m}),a(e,{hook:r,ok:false,error:m.message})}};var x=[{event:plugin.HookEvent.ContextBuildBefore,handler:E},{event:plugin.HookEvent.SessionCompacting,handler:S},{event:plugin.HookEvent.ToolFailure,handler:P}];function O(){return x.map(({event:e,handler:o})=>({event:e,hooks:[{type:"function",handler:o}]}))}var ae=utils.Log.create({service:"memory.plugin.tool"}),se="memory",Y=["recall","remember","update","forget","extract","graph_query","status"],io=new Set(["recall","remember","forget","graph_query","status"]),ne="Access EASBot long-term memory via `op` and `params`.";function ao(){try{let e=utils.loadTextFile("./description.txt",chunkR32346OA_cjs.d)();return e.trim().length>0?e:ne}catch(e){return ae.warn("memory tool description unavailable, using fallback",{error:utils.errorMeta(e)}),ne}}var C=plugin.createTool({description:ao(),args:{op:w__default.default.enum(Y).describe("Operation name"),params:w__default.default.record(w__default.default.string(),w__default.default.unknown()).optional().describe("Operation arguments as a flat object")},execute:async(e,o)=>{let r=String(e.op),t=e.params??{},c=o.agent||"memory-plugin",u=o.worktree||o.directory;try{let s=chunkGCVKM3RJ_cjs.j(u),n={agentId:c,isTrustedLocal:!0,remote:!1,locale:"en-US",dbPath:s,workspaceDir:u,rootDir:u,config:chunkQAEIHJOF_cjs.A({agentId:c,dbPath:s,workspaceDir:u}),signal:o.abort},m=await chunkQAEIHJOF_cjs.z(r,t,n);return io.has(r)?await chunkISYAE6B7_cjs.a(r,m):JSON.stringify(m??{},null,2)}catch(s){let n=utils.errorMeta(s);return ae.error("memory tool execution failed",{op:r,error:n}),`memory tool failed for op "${r}": ${n.message}`}}});var I=async e=>({hooks:O(),tools:{[_.name]:C}});utils.Log.create({service:"memory.plugin.hook"});var me=[plugin.HookEvent.ContextBuildBefore,plugin.HookEvent.SessionCompacting,plugin.HookEvent.ToolFailure];var pe={name:"memory.plugin",async init(){return {isEnabled:()=>true,handlers:x.map(({event:e,handler:o})=>({name:e,handler:o}))}}};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=po;exports.MEMORY_HOOK_BINDINGS=x;exports.MEMORY_HOOK_EVENTS=me;exports.MEMORY_PLUGIN_ID=A;exports.MEMORY_PLUGIN_MANIFEST=_;exports.MEMORY_PLUGIN_VERSION=D;exports.MEMORY_TOOL_ID=se;exports.MEMORY_TOOL_OPS=Y;exports.MemoryPlugin=I;exports.MemoryPluginEntry=I;exports.MemoryPluginHook=pe;exports.MemoryTool=C;exports.addWord=Ho;exports.closeTokenizer=Oo;exports.createMemoryHookMatchers=O;exports.initTokenizer=xo;exports.isInitialized=ho;exports.loadCustomDict=Fe;exports.toFtsTokens=Io;exports.toFtsTokensForSearch=bo;exports.tokenize=Ye;exports.tokenizeForSearch=Be;
|
|
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>
|
|
9
|
+
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>
|
|
15
|
+
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;
|
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
|
|
5
|
+
import { z, ZodTypeAny } 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';
|
|
@@ -638,7 +638,7 @@ 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.
|
|
641
|
+
declare const MEMORY_PLUGIN_VERSION = "0.3.36";
|
|
642
642
|
declare const MEMORY_PLUGIN_MANIFEST: PluginManifest;
|
|
643
643
|
|
|
644
644
|
declare function createMemoryHookMatchers(): HookMatcher[];
|
|
@@ -657,9 +657,56 @@ declare const MemoryPluginHook: HookInfo;
|
|
|
657
657
|
|
|
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
|
+
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>>;
|
|
673
|
+
category: z.ZodOptional<z.ZodEnum<{
|
|
674
|
+
user_preference: "user_preference";
|
|
675
|
+
task_context: "task_context";
|
|
676
|
+
technical_fact: "technical_fact";
|
|
677
|
+
decision: "decision";
|
|
678
|
+
relationship: "relationship";
|
|
679
|
+
reminder: "reminder";
|
|
680
|
+
error_pattern: "error_pattern";
|
|
681
|
+
workflow: "workflow";
|
|
682
|
+
exploration_finding: "exploration_finding";
|
|
683
|
+
experience_summary: "experience_summary";
|
|
684
|
+
tool_usage: "tool_usage";
|
|
685
|
+
skill_creation: "skill_creation";
|
|
686
|
+
test: "test";
|
|
687
|
+
other: "other";
|
|
688
|
+
}>>;
|
|
689
|
+
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>;
|
|
693
|
+
content: z.ZodOptional<z.ZodString>;
|
|
694
|
+
importance: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>;
|
|
695
|
+
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>>;
|
|
700
|
+
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>>;
|
|
704
|
+
relation: z.ZodOptional<z.ZodString>;
|
|
705
|
+
type: z.ZodOptional<z.ZodString>;
|
|
706
|
+
};
|
|
660
707
|
declare const MemoryTool: _easbot_types.ToolDefinition & {
|
|
661
708
|
args: {
|
|
662
|
-
|
|
709
|
+
operation: z.ZodEnum<{
|
|
663
710
|
status: "status";
|
|
664
711
|
recall: "recall";
|
|
665
712
|
forget: "forget";
|
|
@@ -668,8 +715,42 @@ declare const MemoryTool: _easbot_types.ToolDefinition & {
|
|
|
668
715
|
update: "update";
|
|
669
716
|
extract: "extract";
|
|
670
717
|
}>;
|
|
671
|
-
|
|
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>>;
|
|
720
|
+
category: z.ZodOptional<z.ZodEnum<{
|
|
721
|
+
user_preference: "user_preference";
|
|
722
|
+
task_context: "task_context";
|
|
723
|
+
technical_fact: "technical_fact";
|
|
724
|
+
decision: "decision";
|
|
725
|
+
relationship: "relationship";
|
|
726
|
+
reminder: "reminder";
|
|
727
|
+
error_pattern: "error_pattern";
|
|
728
|
+
workflow: "workflow";
|
|
729
|
+
exploration_finding: "exploration_finding";
|
|
730
|
+
experience_summary: "experience_summary";
|
|
731
|
+
tool_usage: "tool_usage";
|
|
732
|
+
skill_creation: "skill_creation";
|
|
733
|
+
test: "test";
|
|
734
|
+
other: "other";
|
|
735
|
+
}>>;
|
|
736
|
+
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>;
|
|
740
|
+
content: z.ZodOptional<z.ZodString>;
|
|
741
|
+
importance: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>;
|
|
742
|
+
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>>;
|
|
747
|
+
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>>;
|
|
751
|
+
relation: z.ZodOptional<z.ZodString>;
|
|
752
|
+
type: z.ZodOptional<z.ZodString>;
|
|
672
753
|
};
|
|
673
754
|
};
|
|
674
755
|
|
|
675
|
-
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_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 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 };
|
|
756
|
+
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 };
|
package/dist/index.d.ts
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
|
|
5
|
+
import { z, ZodTypeAny } 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';
|
|
@@ -638,7 +638,7 @@ 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.
|
|
641
|
+
declare const MEMORY_PLUGIN_VERSION = "0.3.36";
|
|
642
642
|
declare const MEMORY_PLUGIN_MANIFEST: PluginManifest;
|
|
643
643
|
|
|
644
644
|
declare function createMemoryHookMatchers(): HookMatcher[];
|
|
@@ -657,9 +657,56 @@ declare const MemoryPluginHook: HookInfo;
|
|
|
657
657
|
|
|
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
|
+
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>>;
|
|
673
|
+
category: z.ZodOptional<z.ZodEnum<{
|
|
674
|
+
user_preference: "user_preference";
|
|
675
|
+
task_context: "task_context";
|
|
676
|
+
technical_fact: "technical_fact";
|
|
677
|
+
decision: "decision";
|
|
678
|
+
relationship: "relationship";
|
|
679
|
+
reminder: "reminder";
|
|
680
|
+
error_pattern: "error_pattern";
|
|
681
|
+
workflow: "workflow";
|
|
682
|
+
exploration_finding: "exploration_finding";
|
|
683
|
+
experience_summary: "experience_summary";
|
|
684
|
+
tool_usage: "tool_usage";
|
|
685
|
+
skill_creation: "skill_creation";
|
|
686
|
+
test: "test";
|
|
687
|
+
other: "other";
|
|
688
|
+
}>>;
|
|
689
|
+
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>;
|
|
693
|
+
content: z.ZodOptional<z.ZodString>;
|
|
694
|
+
importance: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>;
|
|
695
|
+
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>>;
|
|
700
|
+
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>>;
|
|
704
|
+
relation: z.ZodOptional<z.ZodString>;
|
|
705
|
+
type: z.ZodOptional<z.ZodString>;
|
|
706
|
+
};
|
|
660
707
|
declare const MemoryTool: _easbot_types.ToolDefinition & {
|
|
661
708
|
args: {
|
|
662
|
-
|
|
709
|
+
operation: z.ZodEnum<{
|
|
663
710
|
status: "status";
|
|
664
711
|
recall: "recall";
|
|
665
712
|
forget: "forget";
|
|
@@ -668,8 +715,42 @@ declare const MemoryTool: _easbot_types.ToolDefinition & {
|
|
|
668
715
|
update: "update";
|
|
669
716
|
extract: "extract";
|
|
670
717
|
}>;
|
|
671
|
-
|
|
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>>;
|
|
720
|
+
category: z.ZodOptional<z.ZodEnum<{
|
|
721
|
+
user_preference: "user_preference";
|
|
722
|
+
task_context: "task_context";
|
|
723
|
+
technical_fact: "technical_fact";
|
|
724
|
+
decision: "decision";
|
|
725
|
+
relationship: "relationship";
|
|
726
|
+
reminder: "reminder";
|
|
727
|
+
error_pattern: "error_pattern";
|
|
728
|
+
workflow: "workflow";
|
|
729
|
+
exploration_finding: "exploration_finding";
|
|
730
|
+
experience_summary: "experience_summary";
|
|
731
|
+
tool_usage: "tool_usage";
|
|
732
|
+
skill_creation: "skill_creation";
|
|
733
|
+
test: "test";
|
|
734
|
+
other: "other";
|
|
735
|
+
}>>;
|
|
736
|
+
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>;
|
|
740
|
+
content: z.ZodOptional<z.ZodString>;
|
|
741
|
+
importance: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>, z.ZodNumber>>;
|
|
742
|
+
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>>;
|
|
747
|
+
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>>;
|
|
751
|
+
relation: z.ZodOptional<z.ZodString>;
|
|
752
|
+
type: z.ZodOptional<z.ZodString>;
|
|
672
753
|
};
|
|
673
754
|
};
|
|
674
755
|
|
|
675
|
-
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_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 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 };
|
|
756
|
+
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 };
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
|
-
import {a}from'./chunks/chunk-FZ3RTYIJ.mjs';export{b as MemoryStdioServer,a as renderOperationMarkdown}from'./chunks/chunk-FZ3RTYIJ.mjs';import'./chunks/chunk-QF5S5MG7.mjs';export{a as COMMANDS_HELP,d as handleMemoryCli,b as renderBanner,c as renderHelp}from'./chunks/chunk-YUWHNHAY.mjs';import {A,z}from'./chunks/chunk-AEAMQDNV.mjs';export{y as ALL_OPS,a as GraphStore,x as OP_REGISTRY,r as consolidate,v as doctor,z as executeOp,q as extract,p as forget,t as graphQuery,w as init,b as recall,n as remember,u as status,s as sync,o as update}from'./chunks/chunk-AEAMQDNV.mjs';export{a as LATEST_SCHEMA_VERSION,b as MIGRATIONS,e as MemoryDatabaseManager,d as readCurrentSchemaVersion,c as runMigrations}from'./chunks/chunk-YJLHS7JB.mjs';export{a as Llm}from'./chunks/chunk-HH7EA2UE.mjs';import {a as a$
|
|
2
|
-
${
|
|
3
|
-
`)}`,
|
|
1
|
+
import {a}from'./chunks/chunk-FZ3RTYIJ.mjs';export{b as MemoryStdioServer,a as renderOperationMarkdown}from'./chunks/chunk-FZ3RTYIJ.mjs';import'./chunks/chunk-QF5S5MG7.mjs';export{a as COMMANDS_HELP,d as handleMemoryCli,b as renderBanner,c as renderHelp}from'./chunks/chunk-YUWHNHAY.mjs';import {A as A$1,z as z$1}from'./chunks/chunk-AEAMQDNV.mjs';export{y as ALL_OPS,a as GraphStore,x as OP_REGISTRY,r as consolidate,v as doctor,z as executeOp,q as extract,p as forget,t as graphQuery,w as init,b as recall,n as remember,u as status,s as sync,o as update}from'./chunks/chunk-AEAMQDNV.mjs';export{a as LATEST_SCHEMA_VERSION,b as MIGRATIONS,e as MemoryDatabaseManager,d as readCurrentSchemaVersion,c as runMigrations}from'./chunks/chunk-YJLHS7JB.mjs';import {a as a$1}from'./chunks/chunk-HH7EA2UE.mjs';export{a as Llm}from'./chunks/chunk-HH7EA2UE.mjs';import {a as a$2}from'./chunks/chunk-AJDMZTCQ.mjs';import {d}from'./chunks/chunk-SE3F5YQE.mjs';export{b as DEFAULT_MEMORY_JSON,c as MEMORY_JSON_REL_PATH,d as MemoryCache,a as MemoryJsonSchema}from'./chunks/chunk-SE3F5YQE.mjs';import {j,f as f$1}from'./chunks/chunk-HX3TV7FD.mjs';export{c as getGlobal,g as getHomeDir,f as getInstance,j as getMemoryDbPath,i as getMemoryDir,h as getXdgData,b as resetGlobalAdapter,e as resetInstanceAdapter,a as setGlobalAdapter,d as setInstanceAdapter}from'./chunks/chunk-HX3TV7FD.mjs';import'./chunks/chunk-S4DPVKMV.mjs';export{GRAPH_ENTITY_TYPE_DEFINITIONS,GRAPH_RELATION_TYPE_DEFINITIONS}from'@easbot/types';import*as x from'jieba-wasm';import {Log,loadTextFile,Schema,ServiceError,ServiceErrorBus,errorMeta,NameErrors,Filesystem}from'@easbot/utils';import {HookEvent,createTool}from'@easbot/plugin';import {createHash}from'crypto';import {existsSync}from'fs';import {z}from'zod';var wr=["user_preference","task_context","technical_fact","decision","relationship","reminder","error_pattern","workflow","exploration_finding","experience_summary","tool_usage","skill_creation","test","other"];var f=Log.create({service:"memory.tokenizer"}),M=false,Ye=loadTextFile("./assets/jieba_dict.txt",import.meta.url);async function Fr(e){if(!M)try{f.debug("Initializing jieba tokenizer");let t=Ye();if(x.with_dict(t),f.debug("Built-in dictionary loaded"),e?.dictPath&&e.dictPath.length>0)for(let o of e.dictPath)await qe(o);M=!0,f.debug("Jieba tokenizer initialized successfully");}catch(t){f.error("Failed to initialize jieba tokenizer",{error:errorMeta(t)}),f.warn("Using fallback tokenization (space-based)");}}async function qe(e){if(!M)throw new a$2.TokenizerNotInitializedError({message:"Tokenizer not initialized"});try{let t=await Filesystem.readText(e);f.debug("Loading custom dictionary",{dictPath:e}),x.with_dict(t),f.debug("Custom dictionary loaded successfully",{dictPath:e});}catch(t){f.warn("Failed to load custom dictionary",{dictPath:e,error:errorMeta(t)});}}function je(e){if(!M)return e.split(/\s+/).filter(Boolean);try{return x.cut(e)}catch(t){return f.warn("Tokenization failed, using fallback",{error:errorMeta(t)}),e.split(/\s+/).filter(Boolean)}}function Ke(e){if(!M)return e.split(/\s+/).filter(Boolean);try{return x.cut_for_search(e)}catch(t){return f.warn("Tokenization for search failed, using fallback",{error:errorMeta(t)}),e.split(/\s+/).filter(Boolean)}}function Dr(e,t,o){if(M)try{x.add_word(e,t,o),f.debug("Word added to dictionary",{word:e,freq:t,tag:o});}catch(r){f.warn("Failed to add word",{word:e,error:errorMeta(r)});}}function $r(){return M}async function Br(){M=false,f.debug("Tokenizer closed");}function Yr(e){if(!M)return e.split(/\s+/).filter(Boolean).join(" ");try{return je(e).join(" ")}catch(t){return f.warn("Tokenization failed, using fallback",{error:errorMeta(t)}),e.split(/\s+/).filter(Boolean).join(" ")}}function qr(e){if(!M)return e.split(/\s+/).filter(Boolean).join(" ");try{return Ke(e).join(" ")}catch(t){return f.warn("Tokenization for search failed, using fallback",{error:errorMeta(t)}),e.split(/\s+/).filter(Boolean).join(" ")}}var K="memory",U="0.3.36",C={name:K,version:U,description:"EASBot memory plugin: lifecycle hooks and memory tool",entry:"./index.mjs",capabilities:["hooks","tools"]};function y(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 ce(e){if(typeof e!="object"||e===null)return {};let t=e.extras;return typeof t=="object"&&t!==null&&!Array.isArray(t)?t:{}}function pe(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 h(e,t){let o={...ce(e),...ce(t)};return {agentId:y(t,["agentId"])??pe(e)??pe(t)??y(e,["agentId"])??y(t,["agent"])??y(e,["agent"])??"",sessionId:y(t,["sessionId"])??y(e,["sessionId"]),toolName:y(e,["toolName","tool","name"])??y(t,["toolName"]),error:y(e,["error","message"])??y(t,["error"]),messagePreview:y(e,["messagePreview"])??y(t,["messagePreview"]),contextPreview:y(e,["contextPreview","text","prompt"])??y(t,["contextPreview"]),extras:o}}function I(e){let t=f$1().worktree,o=j(t),r=e.trim()||"memory-plugin";return {agentId:r,isTrustedLocal:true,remote:false,locale:"en-US",dbPath:o,workspaceDir:t,rootDir:t,config:A$1({agentId:r,dbPath:o,workspaceDir:t})}}function g(e,t){return {modified:false,input:e,output:{...t}}}function de(e,t){return {modified:true,input:e,output:{...t}}}function ue(e,t){return y(e,[t])}var Qe=Log.create({service:"memory.plugin.hook"}),A=async(e,t)=>{let o=HookEvent.ContextBuildBefore,r=h(e,t);if(!r.agentId.trim())return g(e,{hook:o,ok:false,error:"context build: agentId is required"});let l=typeof r.extras.topK=="number"?r.extras.topK:5,m=typeof r.extras.query=="string"?r.extras.query:"";try{let c=await z$1("recall",{query:m,maxResults:l},I(r.agentId));if(c.hits.length===0)return g(e,{hook:o,ok:!0,context:[],logLine:"context build: no facts found; skipping context injection"});let i=c.hits.map(B=>`- [${B.category}/imp=${B.importance}] ${B.snippet.slice(0,200)}`),a=`[memory:recall top-${c.hits.length}]
|
|
2
|
+
${i.join(`
|
|
3
|
+
`)}`,k=ue(e,"userMessage");return k===void 0?g(e,{hook:o,ok:!0,context:[a],logLine:`context build: recalled ${c.hits.length} facts (input shape unexpected, not injected)`}):de({...e,userMessage:k?`${a}
|
|
4
4
|
|
|
5
|
-
${
|
|
6
|
-
${
|
|
7
|
-
`)}`;return
|
|
8
|
-
`);try{let
|
|
5
|
+
${k}`:a},{hook:o,ok:!0,context:[a],logLine:`context build: injected ${c.hits.length} facts`})}catch(c){let i=errorMeta(c);return Qe.warn("memory context build hook failed",{error:i}),g(e,{hook:o,ok:false,error:i.message})}};var Ze=Log.create({service:"memory.plugin.hook"}),er=200,L=async(e,t)=>{let o=HookEvent.SessionCompacting,r=h(e,t);if(!r.agentId.trim())return g(e,{hook:o,ok:false,error:"pre compact: agentId is required"});let m=(r.contextPreview??r.messagePreview??"").slice(0,er).replace(/\s+/g," ").trim(),c=typeof r.extras.topK=="number"?r.extras.topK:3;if(!m)return g(e,{hook:o,ok:true,context:[],logLine:"pre compact: empty context preview; skipping recall injection"});try{let i=await z$1("recall",{query:m,maxResults:c,minImportance:5},I(r.agentId));if(i.hits.length===0)return g(e,{hook:o,ok:!0,context:[],logLine:"pre compact: no facts matched query"});let a=i.hits.map(T=>`- [${T.category}/imp=${T.importance}] ${T.snippet.slice(0,150)}`),k=`[memory:pre-compact recall top-${i.hits.length} (imp>=5)]
|
|
6
|
+
${a.join(`
|
|
7
|
+
`)}`;return g(e,{hook:o,ok:!0,context:[k],logLine:`pre compact: injected ${i.hits.length} facts before compaction`})}catch(i){let a=errorMeta(i);return Ze.warn("memory pre compact hook failed",{error:a}),g(e,{hook:o,ok:false,error:a.message})}};var ar=Log.create({service:"memory.plugin.hook"}),ir=8,G=async(e,t)=>{let o=HookEvent.ToolFailure,r=h(e,t);if(!r.agentId.trim())return g(e,{hook:o,ok:false,error:"tool failure: agentId is required"});if(!r.toolName?.trim()||!r.error?.trim())return g(e,{hook:o,ok:false,error:"tool failure: toolName and error are required"});let l=createHash("sha256").update(`${r.toolName}:${r.error}`).digest("hex").slice(0,ir),m=r.messagePreview?r.messagePreview.slice(0,200).replace(/\s+/g," ").trim():"",c=[`[error_pattern] tool=${r.toolName}`,`[error] ${r.error}`,m?`[preview] ${m}`:"",`[errHash] ${l}`].filter(Boolean).join(`
|
|
8
|
+
`);try{let i=await z$1("remember",{content:c,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},I(r.agentId));return g(e,{hook:o,ok:!0,logLine:`tool failure: wrote error_pattern fact ${i.fact.id} (tool=${r.toolName}, errHash=${l})`})}catch(i){let a=errorMeta(i);return ar.warn("memory tool failure hook failed",{error:a}),g(e,{hook:o,ok:false,error:a.message})}};var _=[{event:HookEvent.ContextBuildBefore,handler:A},{event:HookEvent.SessionCompacting,handler:L},{event:HookEvent.ToolFailure,handler:G}];function S(){return _.map(({event:e,handler:t})=>({event:e,hooks:[{type:"function",handler:t}]}))}var w=Log.create({service:"memory.plugin.tool"}),Q="memory",F=["recall","remember","update","forget","extract","graph_query","status"],ur=500,ge="Access EASBot long-term memory via `operation` (recall / remember / update / forget / extract / graph_query / status).",D=z.enum(["user_preference","task_context","technical_fact","decision","relationship","reminder","error_pattern","workflow","exploration_finding","experience_summary","tool_usage","skill_creation","test","other"]),gr=z.object({operation:z.literal("recall"),query:z.string().describe("Search query text"),limit:Schema.positiveInt.optional().default(10).describe("Max results (default 10)"),category:D.optional().describe("Filter by memory category"),minImportance: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: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:z.boolean().optional().default(false).describe("Include KG neighbor subgraph (default false)"),includeShared:z.boolean().optional().default(false).describe("Include shared KG nodes from other agents (default false)")}).strict(),fr=z.object({operation:z.literal("remember"),content:z.string().describe("Memory content"),category:D.describe("Memory category"),importance:Schema.positiveInt.describe("Importance 1-10 (service layer enforces range)"),tags:Schema.stringArray.optional().describe("Optional tags (string[])")}).strict(),yr=z.object({operation:z.literal("update"),factId:z.string().describe("Target fact id (must belong to ctx.agentId)"),content:z.string().optional().describe("New content (triggers embedding rewrite + FTS reindex)"),category:D.optional().describe("New category"),importance:Schema.positiveInt.optional().describe("New importance 1-10"),tags: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`"}),Mr=z.object({operation:z.literal("forget"),factId:z.string().describe("Target fact id to delete (must belong to ctx.agentId)"),dryRun:z.boolean().optional().default(false).describe("Preview without deleting (returns matched count, never deletes)"),force:z.boolean().optional().default(false).describe("Skip KG reference check and delete anyway (use after dryRun confirms the match)")}).strict(),xr=z.object({operation:z.literal("extract"),lastN:Schema.positiveInt.optional().default(10).describe("Recent messages (default 10)"),fromMessageId:z.string().optional().describe("Process messages after this id")}).strict(),kr=z.object({operation:z.literal("graph_query"),query: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:Schema.positiveInt.optional().describe("KG node id to start BFS from (alternative to `query`)"),maxDepth:Schema.positiveInt.optional().default(2).describe("BFS depth for neighbor expansion (default 2; range [1, 5])"),maxNodes:Schema.nonNegativeInt.optional().default(100).describe("Max nodes returned after BFS (default 100; service max 500)"),maxEdgesPerNode: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:z.string().optional().describe('Edge relation filter (e.g. "uses"; single-value exact match)'),type: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)"}),br=z.object({operation:z.literal("status")}).strict(),hr={recall:gr,remember:fr,update:yr,forget:Mr,extract:xr,graph_query:kr,status:br},$={operation:z.enum(F).describe("Operation to run (exactly one per call)"),query:z.string().optional().describe("recall: search query text / graph_query: node name fragment"),limit:Schema.positiveInt.optional().describe("recall: max results (default 10, max 100)"),category:D.optional().describe("remember/update: memory category / recall: category filter"),minImportance:Schema.positiveInt.optional().describe("recall: INCLUSIVE `>=` filter on the 1-10 importance scale"),maxEdgesPerNode:Schema.positiveInt.optional().describe("recall/graph_query: max edges per KG neighbor node (default 10, max 100)"),includeGraph:z.boolean().optional().describe("recall: include KG neighbor subgraph (default false)"),includeShared:z.boolean().optional().describe("recall: include shared KG nodes from other agents (default false)"),content:z.string().optional().describe("remember/update: fact body"),importance:Schema.positiveInt.optional().describe("remember/update: importance 1-10"),tags:Schema.stringArray.optional().describe("remember/update: tags (string[] or comma-separated string)"),factId:z.string().optional().describe("update/forget: target fact id"),dryRun:z.boolean().optional().describe("forget: preview without deleting (default false)"),force:z.boolean().optional().describe("forget: skip KG reference check and delete anyway (default false)"),lastN:Schema.positiveInt.optional().describe("extract: recent messages to scan (default 10)"),fromMessageId:z.string().optional().describe("extract: process messages after this id"),nodeId:Schema.positiveInt.optional().describe("graph_query: KG node id to start BFS from"),maxDepth:Schema.positiveInt.optional().describe("graph_query: BFS depth (default 2, max 5)"),maxNodes:Schema.nonNegativeInt.optional().describe("graph_query: max nodes returned after BFS (default 100, max 500)"),relation:z.string().optional().describe("graph_query: edge relation filter (single-value exact match)"),type:z.string().optional().describe("graph_query: node type filter for root node")};function Ir(){try{let e=loadTextFile("./memory.txt",import.meta.url)();return e.trim().length>0?e:ge}catch(e){return w.warn("memory tool description unavailable, using fallback",{error:errorMeta(e)}),ge}}function _r(e){let t=e.agent?.trim();if(!t)throw new NameErrors.MissingFieldError({message:"memory tool: agentId is required (ctx.agent must be set)",field:"agentId"});return t}function Or(e,t){let o=hr[e],r={};for(let m of Object.keys(o.shape))r[m]=t[m];let l=o.safeParse({...r,operation:e});if(!l.success){let m=l.error.issues.map(c=>`${c.path.join(".")||"(root)"}: ${c.message}`).join("; ");throw new NameErrors.InvalidArgumentError({message:`memory tool: invalid parameters for operation "${e}" \u2014 ${m}`,param:e})}return l.data}async function Rr(e,t){let o=j(e);if(!existsSync(o)){w.debug("memory db not found, auto-initializing",{dbPath:o,workspaceDir:e});try{await z$1("init",{workspaceDir:e,force:!1},t);}catch(r){throw new NameErrors.OperationFailedError({message:`memory tool: auto-init failed (${errorMeta(r).message}). Try running \`easbot memory init\` manually.`,operation:"memory-auto-init"})}}}async function Hr(){if(!(a$1.isInitialized()&&a$1.capabilities().graph))try{let e=await d.getMemoryJson();a$1.init({models:{embedding:e?.embedding_model??void 0,graph:e?.graph_model??void 0}});}catch(e){w.warn("memory Llm init failed; KG extraction will be skipped",{error:errorMeta(e)});}}var P=createTool({description:Ir(),args:$,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=Or(o,e),l=_r(t),m=t.worktree||t.directory||process.cwd(),c=j(m),i={agentId:l,isTrustedLocal:!0,remote:!1,locale:"en-US",dbPath:c,workspaceDir:m,rootDir:m,config:A$1({agentId:l,dbPath:c,workspaceDir:m}),signal:t.abort};switch(await Hr(),await Rr(m,i),o){case "recall":{let a$1=await z$1("recall",{query:r.query,maxResults:r.limit,category:r.category,minImportance:r.minImportance,maxEdgesPerNode:r.maxEdgesPerNode,includeGraph:r.includeGraph,includeShared:r.includeShared,snippetMaxChars:ur},i);return await a("recall",a$1,{toolName:"memory_recall",query:r.query,agentId:l,scope:r.includeShared?"both":"agent_only"})}case "remember":{let a=await z$1("remember",{content:r.content,category:r.category,importance:r.importance,tags:r.tags,sessionId:t.sessionId},i);return `<memory_result>
|
|
9
|
+
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 z$1("update",{factId:r.factId,content:r.content,category:r.category,importance:r.importance,tags:r.tags},i),k=a.fieldsUpdated?.join(", ")??"none";return `<memory_result>
|
|
15
|
+
Memory updated.
|
|
16
|
+
id: ${r.factId}
|
|
17
|
+
updated fields: ${k}
|
|
18
|
+
content changed: ${a.contentChanged}
|
|
19
|
+
</memory_result>`}case "forget":{let a$1=await z$1("forget",{factId:r.factId,dryRun:r.dryRun,force:r.force},i);return await a("forget",a$1)}case "extract":{let a=await z$1("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$1=await z$1("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 a("graph_query",a$1)}case "status":{let a$1=await z$1("status",{},i);return await a("status",a$1)}}}catch(r){if(r instanceof ServiceError)try{return ServiceErrorBus.toMarkdown(r,{tool:"memory",operation:o,resultTag:"<memory_result>",pack:"memory"})}catch(l){return w.error("memory tool ServiceErrorBus formatting failed",{error:errorMeta(l)}),`<memory_result>
|
|
25
|
+
Error: ${r.message}
|
|
26
|
+
</memory_result>`}return w.error("memory tool execution failed",{operation:o,error:errorMeta(r)}),`<memory_result>
|
|
27
|
+
Error: ${errorMeta(r).message}
|
|
28
|
+
</memory_result>`}}});var N=async e=>({hooks:S(),tools:{[C.name]:P}});Log.create({service:"memory.plugin.hook"});var fe=[HookEvent.ContextBuildBefore,HookEvent.SessionCompacting,HookEvent.ToolFailure];var ye={name:"memory.plugin",async init(){return {isEnabled:()=>true,handlers:_.map(({event:e,handler:t})=>({name:e,handler:t}))}}};export{wr as MEMORY_CATEGORIES,_ as MEMORY_HOOK_BINDINGS,fe as MEMORY_HOOK_EVENTS,K as MEMORY_PLUGIN_ID,C as MEMORY_PLUGIN_MANIFEST,U as MEMORY_PLUGIN_VERSION,$ as MEMORY_TOOL_ARGS,Q as MEMORY_TOOL_ID,F as MEMORY_TOOL_OPS,N as MemoryPlugin,N as MemoryPluginEntry,ye as MemoryPluginHook,P as MemoryTool,Dr as addWord,Br as closeTokenizer,S as createMemoryHookMatchers,Fr as initTokenizer,$r as isInitialized,qe as loadCustomDict,Yr as toFtsTokens,qr as toFtsTokensForSearch,je as tokenize,Ke as tokenizeForSearch};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easbot/memory",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.37",
|
|
4
4
|
"description": "Memory management library for EASBOT ecosystem - 智能记忆管理库,支持混合搜索、中英文分词、增量索引",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -53,15 +53,15 @@
|
|
|
53
53
|
"ai": "^6.0.253",
|
|
54
54
|
"better-sqlite3": "^13.0.3",
|
|
55
55
|
"jieba-wasm": "^2.4.0",
|
|
56
|
-
"@easbot/database": "0.3.
|
|
57
|
-
"@easbot/
|
|
58
|
-
"@easbot/
|
|
59
|
-
"@easbot/types": "0.3.
|
|
60
|
-
"@easbot/
|
|
61
|
-
"@easbot/
|
|
62
|
-
"@easbot/
|
|
63
|
-
"@easbot/
|
|
64
|
-
"@easbot/
|
|
56
|
+
"@easbot/database": "0.3.37",
|
|
57
|
+
"@easbot/mcp": "0.3.37",
|
|
58
|
+
"@easbot/plugin": "0.3.37",
|
|
59
|
+
"@easbot/types": "0.3.37",
|
|
60
|
+
"@easbot/utils": "0.3.37",
|
|
61
|
+
"@easbot/terminal": "0.3.37",
|
|
62
|
+
"@easbot/llm": "0.3.37",
|
|
63
|
+
"@easbot/local-model-sdk": "0.3.37",
|
|
64
|
+
"@easbot/ollama-sdk": "0.3.37"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@types/node": "^25.9.5",
|
|
@@ -83,6 +83,8 @@
|
|
|
83
83
|
"test:run": "vitest run",
|
|
84
84
|
"test:coverage": "vitest run --coverage",
|
|
85
85
|
"test:clean": "tsx scripts/clean-test-fixtures.ts",
|
|
86
|
+
"plugin:generate": "tsx scripts/generate-plugin-distribution.ts",
|
|
87
|
+
"plugin:check": "tsx scripts/generate-plugin-distribution.ts --check",
|
|
86
88
|
"lint": "biome check .",
|
|
87
89
|
"lint:fix": "biome check --write .",
|
|
88
90
|
"lint:report": "biome check --reporter=summary .",
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
WHEN TO USE:
|
|
2
|
-
Use this tool to read or write EASBot long-term memory. Call it when the user asks to remember something, when you need prior facts or error patterns before answering, or when you need the memory subsystem health status.
|
|
3
|
-
|
|
4
|
-
AFTER THIS:
|
|
5
|
-
Review the returned markdown or JSON. For `recall`, use the returned facts as context and cite them when relevant. For `remember` / `update` / `forget`, report the affected fact id. For `status`, report the health summary.
|
|
6
|
-
|
|
7
|
-
NOTES:
|
|
8
|
-
- `op` selects one of: recall, remember, update, forget, extract, graph_query, status.
|
|
9
|
-
- `params` carries the operation arguments as a flat object; see the memory op schemas for field names.
|
|
10
|
-
- Operations run against the current workspace memory database. Write operations require a trusted local caller.
|
|
11
|
-
- `update` / `extract` return JSON text; the other operations return rendered markdown.
|
|
12
|
-
- Failures return a diagnostic string instead of throwing. Keep going with the rest of the task.
|