@easbot/memory 0.3.13 → 0.3.16
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 +216 -38
- package/README.md +213 -38
- package/dist/chunks/chunk-3HTZTI7U.cjs +1 -0
- package/dist/chunks/chunk-5W4K5UKV.mjs +53 -0
- package/dist/chunks/chunk-7XEOH55R.cjs +1 -0
- package/dist/chunks/chunk-BWPPLYIF.cjs +1 -0
- package/dist/chunks/chunk-FEMOFIOS.mjs +1 -0
- package/dist/chunks/chunk-FNT7WEHL.mjs +1 -0
- package/dist/chunks/chunk-I5YWAJHW.cjs +32 -0
- package/dist/chunks/chunk-JGXW3E73.mjs +59 -0
- package/dist/chunks/chunk-MQ72K25M.cjs +59 -0
- package/dist/chunks/chunk-NJVXQ7TV.cjs +1 -0
- package/dist/chunks/chunk-OWLFPNZG.cjs +1 -0
- package/dist/chunks/chunk-PWLSQFYA.mjs +32 -0
- package/dist/chunks/chunk-Q2MKNRER.cjs +53 -0
- package/dist/chunks/chunk-QF5S5MG7.mjs +0 -0
- package/dist/chunks/chunk-URADAZYW.cjs +1 -0
- package/dist/chunks/chunk-WQGSYA5D.mjs +1 -0
- package/dist/chunks/chunk-YHOJKRHE.mjs +1 -0
- package/dist/chunks/chunk-Z3NQERNT.mjs +1 -0
- package/dist/chunks/cli-handler-57MKQCNO.cjs +1 -0
- package/dist/chunks/cli-handler-WW3I2YV4.mjs +1 -0
- package/dist/chunks/config-BFJFRX2C.cjs +1 -0
- package/dist/chunks/config-M2KZYVRZ.mjs +1 -0
- package/dist/chunks/consolidate-YQ3H643L.cjs +2 -0
- package/dist/chunks/consolidate-ZCFRYIWV.mjs +2 -0
- package/dist/chunks/doctor-GVSMK4HL.cjs +2 -0
- package/dist/chunks/doctor-SPJ64FW3.mjs +2 -0
- package/dist/chunks/extract-5VSCY754.mjs +2 -0
- package/dist/chunks/extract-E54PPHMQ.cjs +2 -0
- package/dist/chunks/forget-AALO5DL5.mjs +3 -0
- package/dist/chunks/forget-GEAEUNRH.cjs +3 -0
- package/dist/chunks/graph-HSYCZI7R.mjs +3 -0
- package/dist/chunks/graph-QEGKUROQ.cjs +3 -0
- package/dist/chunks/init-2GZLH6RB.cjs +2 -0
- package/dist/chunks/init-U7XRD4MW.mjs +2 -0
- package/dist/chunks/interfaces-KNVKCV3Q.cjs +1 -0
- package/dist/chunks/interfaces-VBO3Z6QF.mjs +1 -0
- package/dist/chunks/mcp-WE7TV32J.cjs +1 -0
- package/dist/chunks/mcp-XPTJOCQA.mjs +1 -0
- package/dist/chunks/recall-JI2NYDLH.cjs +2 -0
- package/dist/chunks/recall-M6SAHHZX.mjs +2 -0
- package/dist/chunks/remember-FR5QGXFT.mjs +2 -0
- package/dist/chunks/remember-X33PMYA5.cjs +2 -0
- package/dist/chunks/status-6XW6Q3TT.mjs +2 -0
- package/dist/chunks/status-CPB6XZNU.cjs +2 -0
- package/dist/chunks/stdio-server-5LE3HFKN.mjs +1 -0
- package/dist/chunks/stdio-server-6PUOFDLR.cjs +1 -0
- package/dist/cli.cjs +2 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.mjs +2 -0
- package/dist/index.cjs +6 -146
- package/dist/index.d.cts +354 -170
- package/dist/index.d.ts +354 -170
- package/dist/index.mjs +6 -146
- package/package.json +21 -14
package/README.en.md
CHANGED
|
@@ -2,15 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
[中文](./README.md) | English
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Long-term memory library for the EASBOT ecosystem, providing per-agent fact storage, hybrid search, KG scope filtering, and a 9-op unified execution interface.
|
|
6
6
|
|
|
7
|
-
## Features
|
|
7
|
+
## Features (v0.4.0)
|
|
8
8
|
|
|
9
|
-
- **
|
|
10
|
-
- **
|
|
11
|
-
- **
|
|
12
|
-
- **
|
|
13
|
-
- **
|
|
9
|
+
- **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)`.
|
|
10
|
+
- **Per-agent isolation + KG scope filtering** — each KG node carries `owner_agent_id`; scope ∈ `{agent_only, shared_only, both}`; MCP defaults to `agent_only`, trusted local may use `both`.
|
|
11
|
+
- **Layered memory** — short-term / writable self-memory / long-term history; hybrid search (FTS + vector + graph).
|
|
12
|
+
- **Observability** — 9 op fully routed through `Log.create({ service })` English structured logs; `status` / `doctor` provide offline diagnostics.
|
|
13
|
+
- **i18n** — `zh-CN` / `en-US` locales; `@easbot/memory` API logs stay English, copy goes through `t()`.
|
|
14
|
+
- **Portable** — pure TS 6.x; depends on `better-sqlite3` (transitive via `@easbot/database`) + `@easbot/database` (sync facade) + `@easbot/types` / `@easbot/utils` (decision 0036 unified facade; do not directly require `better-sqlite3` / `@modelcontextprotocol/sdk`).
|
|
15
|
+
- **Three-package unified backend support** (decision 0036 / 0049 / 0051 / 0052): database goes through `@easbot/database` `createSyncSqliteConnection`; MCP goes through `@easbot/mcp` `ToolRegistry` + `createAndStartStdioServer`; CLI output goes through `@easbot/terminal` `printHuman` + `emitJsonOk` + `COMMANDS_HELP` single source of truth.
|
|
14
16
|
|
|
15
17
|
## Installation
|
|
16
18
|
|
|
@@ -20,60 +22,236 @@ pnpm add @easbot/memory
|
|
|
20
22
|
|
|
21
23
|
## Usage
|
|
22
24
|
|
|
25
|
+
### 9 op entry
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { executeOp } from '@easbot/memory';
|
|
29
|
+
|
|
30
|
+
// v0.4.0 simplification: no more `createMemorySystem` + `setOpSystem` main class;
|
|
31
|
+
// all ops go through `executeOp(name, args, ctx)` (agentId injected via ctx).
|
|
32
|
+
|
|
33
|
+
// 1. recall
|
|
34
|
+
const recall = await executeOp<{ hits: unknown[] }>(
|
|
35
|
+
'recall',
|
|
36
|
+
{
|
|
37
|
+
// No more agentId at args top-level — goes through ctx.agentId
|
|
38
|
+
query: 'user preference',
|
|
39
|
+
limit: 10,
|
|
40
|
+
scope: 'agent_only',
|
|
41
|
+
// dbPath / workspaceDir go through ctx or service config; can be omitted
|
|
42
|
+
dbPath: '/path/to/memory.db',
|
|
43
|
+
workspaceDir: '/path/to/workspace',
|
|
44
|
+
rootDir: '/path/to/workspace',
|
|
45
|
+
locale: 'en-US',
|
|
46
|
+
remote: false,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
agentId: 'agent-1',
|
|
50
|
+
isTrustedLocal: true,
|
|
51
|
+
},
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
// 2. remember
|
|
55
|
+
const saved = await executeOp<{ id: string }>(
|
|
56
|
+
'remember',
|
|
57
|
+
{
|
|
58
|
+
content: '老侯 prefers TypeScript',
|
|
59
|
+
category: 'user_preference',
|
|
60
|
+
importance: 9,
|
|
61
|
+
dbPath: '/path/to/memory.db',
|
|
62
|
+
workspaceDir: '/path/to/workspace',
|
|
63
|
+
rootDir: '/path/to/workspace',
|
|
64
|
+
locale: 'en-US',
|
|
65
|
+
remote: false,
|
|
66
|
+
},
|
|
67
|
+
{ agentId: 'agent-1', isTrustedLocal: true },
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
// 3. forget (delete by category)
|
|
71
|
+
await executeOp(
|
|
72
|
+
'forget',
|
|
73
|
+
{
|
|
74
|
+
category: 'user_preference',
|
|
75
|
+
maxDelete: 1000,
|
|
76
|
+
dryRun: false,
|
|
77
|
+
dbPath: '/path/to/memory.db',
|
|
78
|
+
workspaceDir: '/path/to/workspace',
|
|
79
|
+
rootDir: '/path/to/workspace',
|
|
80
|
+
locale: 'en-US',
|
|
81
|
+
remote: false,
|
|
82
|
+
},
|
|
83
|
+
{ agentId: 'agent-1', isTrustedLocal: true },
|
|
84
|
+
);
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### KG scope three tiers
|
|
88
|
+
|
|
23
89
|
```typescript
|
|
24
|
-
|
|
90
|
+
// Only this Agent's nodes (default; MCP entry enforces)
|
|
91
|
+
await executeOp('graph_query', { agentId: 'agent-1', kind: 'nodes', scope: 'agent_only' }, { agentId: 'agent-1', isTrustedLocal: true });
|
|
92
|
+
|
|
93
|
+
// Only shared nodes
|
|
94
|
+
await executeOp('graph_query', { agentId: 'agent-1', kind: 'nodes', scope: 'shared_only' }, { agentId: 'agent-1', isTrustedLocal: true });
|
|
95
|
+
|
|
96
|
+
// This Agent + shared (trusted local only; MCP entry rejects)
|
|
97
|
+
await executeOp('graph_query', { agentId: 'agent-1', kind: 'nodes', scope: 'both' }, { agentId: 'agent-1', isTrustedLocal: true });
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Markdown render
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
import { renderOperationMarkdown } from '@easbot/memory';
|
|
104
|
+
const md = await renderOperationMarkdown('recall', recallResult, { toolName: 'memory_recall' });
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## 9 op manifest
|
|
108
|
+
|
|
109
|
+
| op | trusted local only | requires agentId | purpose |
|
|
110
|
+
|---|---|---|---|
|
|
111
|
+
| `recall` | ❌ | ✅ | Hybrid search (FTS + vector + graph) |
|
|
112
|
+
| `remember` | ❌ | ✅ | Persist a self-memory fact |
|
|
113
|
+
| `forget` | ❌ | ✅ | Delete by factId / category / time window (supports `dryRun`) |
|
|
114
|
+
| `extract` | ❌ | ✅ | Aggregate facts / KG nodes for a sessionId |
|
|
115
|
+
| `consolidate` | ✅ | ✅ | dedup → archive pipeline |
|
|
116
|
+
| `graph_query` | ❌ (scope=both → ✅) | ✅ | KG nodes / edges / BFS neighbors |
|
|
117
|
+
| `status` | ❌ | ⚠️ optional | System status snapshot |
|
|
118
|
+
| `doctor` | ✅ | ⚠️ optional | Data integrity checks (supports `repair`) |
|
|
119
|
+
| `init` | ✅ | ⚠️ optional | Initialize workspace (supports `force`) |
|
|
25
120
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
121
|
+
**Local-only operations** (`consolidate`, `doctor`, `init`) reject non-trusted callers; remote / multi-tenant contexts must not invoke them.
|
|
122
|
+
|
|
123
|
+
## API categories
|
|
124
|
+
|
|
125
|
+
### services (9 op business layer)
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
import { recall, remember, forget, extract, consolidate, graphQuery, status, doctor, init } from '@easbot/memory/services';
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### operations (9 op registry + executeOp)
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
import { executeOp, OP_REGISTRY, ALL_OPS } from '@easbot/memory/operations';
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### format (schema + markdown + text + truncate + render)
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
import { renderOperationMarkdown } from '@easbot/memory/format/render';
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### hooks (4 hook types)
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
import type { PreCompactHook, SessionStartHook, SessionEndHook, PostToolFailureHook } from '@easbot/memory/hooks';
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## CLI / MCP dual entry (v0.4 stage 4)
|
|
150
|
+
|
|
151
|
+
### Standalone CLI (`easbot-memory`)
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
# Installed via package.json bin: easbot-memory
|
|
155
|
+
easbot-memory init --workspace-dir <dir>
|
|
156
|
+
easbot-memory status [--agent <id>] [--json]
|
|
157
|
+
easbot-memory doctor [--repair]
|
|
158
|
+
easbot-memory recall --query <q> [--agent <id>] [--limit <n>] [--json]
|
|
159
|
+
easbot-memory remember --content <text> --category <c> --importance <1-10>
|
|
160
|
+
easbot-memory forget [--agent <id>] [--fact-id <id>] [--dry-run]
|
|
161
|
+
easbot-memory extract --session <sessionId> [--last-n <n>]
|
|
162
|
+
easbot-memory consolidate [--agent <id>] [--window-days <n>]
|
|
163
|
+
easbot-memory graph --kind <nodes|edges|neighbors> [--query <q>]>]
|
|
164
|
+
easbot-memory config [--json]
|
|
165
|
+
easbot-memory mcp
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Agent delegation (v0.4 stage 4)
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
# @easbot/agent memory subcommand delegates to @easbot/memory's cli-handler
|
|
172
|
+
easbot memory recall --query "user preference"
|
|
173
|
+
easbot memory remember --content "..." --category user_preference --importance 8
|
|
174
|
+
easbot memory mcp # starts MCP stdio server
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### MCP stdio server (v0.4 stage 4)
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
import { MemoryStdioServer } from '@easbot/memory';
|
|
181
|
+
|
|
182
|
+
// Start 9 tool MCP stdio server (callable by Cline / Claude Code / Continue)
|
|
183
|
+
// v0.4.0: start signature simplified — no `system` param needed (handlers dispatch via executeOp)
|
|
184
|
+
await MemoryStdioServer.start({
|
|
185
|
+
name: 'easbot-memory',
|
|
186
|
+
version: '0.4.0',
|
|
187
|
+
description: 'EASBot memory MCP server',
|
|
29
188
|
});
|
|
30
189
|
|
|
31
|
-
//
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
190
|
+
// List 9 tool names
|
|
191
|
+
const tools = MemoryStdioServer.getToolNames();
|
|
192
|
+
// ['memory_recall', 'memory_remember', 'memory_forget', ...]
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
**9 tool manifest** (1:1 with `OP_REGISTRY`):
|
|
196
|
+
- `memory_recall` / `memory_remember` / `memory_forget` / `memory_extract` / `memory_consolidate` / `memory_graph_query` / `memory_status` / `memory_doctor` / `memory_init`
|
|
197
|
+
|
|
198
|
+
### handleMemoryCli delegation
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
import { handleMemoryCli, setGlobalAdapter, setInstanceAdapter } from '@easbot/memory';
|
|
202
|
+
|
|
203
|
+
// 1. Inject adapters (cli path / agent path)
|
|
204
|
+
setGlobalAdapter({ Path: { /* ... */ } });
|
|
205
|
+
setInstanceAdapter({ directory: process.cwd(), worktree: process.cwd() });
|
|
206
|
+
|
|
207
|
+
// 2. Delegate to unified handler
|
|
208
|
+
const result = await handleMemoryCli(['recall', '--query', 'test'], {
|
|
209
|
+
version: '0.4.0',
|
|
210
|
+
cwd: process.cwd(),
|
|
35
211
|
});
|
|
36
212
|
|
|
37
|
-
|
|
38
|
-
await manager.indexFile('/path/to/file.md');
|
|
213
|
+
if (result.code !== 0) process.exit(result.code);
|
|
39
214
|
```
|
|
40
215
|
|
|
41
|
-
##
|
|
216
|
+
## Database location
|
|
217
|
+
|
|
218
|
+
Default storage: `$XDG_DATA_HOME/easbot/memory.db`
|
|
219
|
+
|
|
220
|
+
- Linux: `~/.local/share/easbot/memory.db`
|
|
221
|
+
- macOS: `~/Library/Application Support/easbot/memory.db`
|
|
222
|
+
- Windows: `%APPDATA%/easbot/memory.db`
|
|
42
223
|
|
|
43
|
-
|
|
224
|
+
## Decisions and migration
|
|
44
225
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
226
|
+
- ADR 0055 / 0056 / 0057 (v0.4 decisions): `docs/decisions/00NN-*.md`
|
|
227
|
+
- v0.4 cleanup log: `.easbot/knowledge/tasks/memory-v04-refactor/`
|
|
228
|
+
- Migration script: `pnpm migrate:v04` (BC-01 ~ BC-12 dry-run + apply)
|
|
229
|
+
- CI guards (v0.4 stage 5 three-package unified backend support):
|
|
230
|
+
- `scripts/check-database-facade.sh` (forbid directly requiring `better-sqlite3` / `node:sqlite` / `createRequire`)
|
|
231
|
+
- `scripts/check-mcp-facade.sh` (forbid directly importing `@modelcontextprotocol/sdk`)
|
|
232
|
+
- `scripts/check-terminal-facade.sh` (CLI output goes through `@easbot/terminal` + `COMMANDS_HELP` single source of truth)
|
|
233
|
+
- `scripts/check-cmd-i18n-coverage.sh` (zh-CN / / en-US dual-locale consistency + switch-case routing validation)
|
|
234
|
+
- L-M13 / L-M14 / L-M15 lessons: `.easbot/knowledge/tasks/memory-v04-refactor/findings.md`
|
|
52
235
|
|
|
53
236
|
## Development
|
|
54
237
|
|
|
55
238
|
```bash
|
|
56
|
-
# Install
|
|
239
|
+
# Install
|
|
57
240
|
pnpm install
|
|
58
241
|
|
|
59
242
|
# Build
|
|
60
243
|
pnpm build
|
|
61
244
|
|
|
62
|
-
# Test
|
|
63
|
-
pnpm test
|
|
245
|
+
# Test (vitest 4)
|
|
246
|
+
pnpm test:run
|
|
64
247
|
|
|
65
248
|
# Type check
|
|
66
249
|
pnpm type-check
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
## Database Location
|
|
70
|
-
|
|
71
|
-
Default storage: `$XDG_DATA_HOME/easbot/memory.db`
|
|
72
250
|
|
|
73
|
-
|
|
74
|
-
-
|
|
75
|
-
|
|
251
|
+
# Lint (biome 2.x)
|
|
252
|
+
pnpm biome-lint
|
|
253
|
+
```
|
|
76
254
|
|
|
77
255
|
## License
|
|
78
256
|
|
|
79
|
-
MIT
|
|
257
|
+
MIT
|
package/README.md
CHANGED
|
@@ -2,15 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
[English](./README.en.md) | 中文
|
|
4
4
|
|
|
5
|
-
EASBOT
|
|
5
|
+
EASBOT 生态系统的长期记忆管理库(v0.4.0)。提供分层记忆、KG scope 三档隔离、9 op 统一调度、混合搜索与可观测治理。
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## 特性(v0.4.0)
|
|
8
8
|
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
- **
|
|
9
|
+
- **9 op 统一入口**:`recall / remember / forget / extract / consolidate / graph_query / status / doctor / init`,MCP / CLI / Agent Tool 三端共享。
|
|
10
|
+
- **KG scope 三档隔离**:每个节点带 `owner_agent_id`;`scope ∈ {agent_only, shared_only, both}`;MCP 默认 `agent_only`,trusted local 可 `both`。
|
|
11
|
+
- **分层记忆**:短期 / 可写自记忆 / 历史长期记忆三层,**混合搜索**(FTS + 向量 + 图)。
|
|
12
|
+
- **可观测性**:9 op 全部走 `Log.create({ service })` 英文结构化日志;`status` / `doctor` 提供离线诊断。
|
|
13
|
+
- **i18n**:`zh-CN` / `en-US` 双 locale;`@easbot/memory` API 日志保持英文,文案走 `t()`。
|
|
14
|
+
- **可移植**:纯 TS 6.x;依赖 `better-sqlite3`(transitive via `@easbot/database`)+ `@easbot/database`(sync facade)+ `@easbot/types` / `@easbot/utils`(决策 0036 统一封装,禁止直接 require better-sqlite3 / @modelcontextprotocol/sdk)。
|
|
15
|
+
- **三包统一后台支撑**(决策 0036 / 0049 / 0051 / 0052):database 走 `@easbot/database` `createSyncSqliteConnection`;MCP 走 `@easbot/mcp` `ToolRegistry` + `createAndStartStdioServer`;CLI 输出走 `@easbot/terminal` `printHuman` + `emitJsonOk` + `COMMANDS_HELP` 单一数据源。
|
|
14
16
|
|
|
15
17
|
## 安装
|
|
16
18
|
|
|
@@ -20,50 +22,193 @@ pnpm add @easbot/memory
|
|
|
20
22
|
|
|
21
23
|
## 使用示例
|
|
22
24
|
|
|
25
|
+
### 9 op 入口
|
|
26
|
+
|
|
23
27
|
```typescript
|
|
24
|
-
import {
|
|
28
|
+
import { executeOp } from '@easbot/memory';
|
|
29
|
+
|
|
30
|
+
// v0.4.0 简化:不再有 `createMemorySystem` + `setOpSystem` 主类;
|
|
31
|
+
// 全部 op 走 `executeOp(name, args, ctx)` 统一入口(agentId 走 ctx 注入)。
|
|
32
|
+
|
|
33
|
+
// 1. recall
|
|
34
|
+
const recall = await executeOp<{ hits: unknown[] }>(
|
|
35
|
+
'recall',
|
|
36
|
+
{
|
|
37
|
+
// 不再传 agentId 到 args 顶层 —— 走 ctx.agentId
|
|
38
|
+
query: 'user preference',
|
|
39
|
+
limit: 10,
|
|
40
|
+
scope: 'agent_only',
|
|
41
|
+
// dbPath / workspaceDir 走 ctx 或 service 配置;可省略
|
|
42
|
+
dbPath: '/path/to/memory.db',
|
|
43
|
+
workspaceDir: '/path/to/workspace',
|
|
44
|
+
rootDir: '/path/to/workspace',
|
|
45
|
+
locale: 'en-US',
|
|
46
|
+
remote: false,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
agentId: 'agent-1',
|
|
50
|
+
isTrustedLocal: true,
|
|
51
|
+
},
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
// 2. remember
|
|
55
|
+
const saved = await executeOp<{ id: string }>(
|
|
56
|
+
'remember',
|
|
57
|
+
{
|
|
58
|
+
content: '老侯 prefers TypeScript',
|
|
59
|
+
category: 'user_preference',
|
|
60
|
+
importance: 9,
|
|
61
|
+
dbPath: '/path/to/memory.db',
|
|
62
|
+
workspaceDir: '/path/to/workspace',
|
|
63
|
+
rootDir: '/path/to/workspace',
|
|
64
|
+
locale: 'en-US',
|
|
65
|
+
remote: false,
|
|
66
|
+
},
|
|
67
|
+
{ agentId: 'agent-1', isTrustedLocal: true },
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
// 3. forget(按 category 全删)
|
|
71
|
+
await executeOp(
|
|
72
|
+
'forget',
|
|
73
|
+
{
|
|
74
|
+
category: 'user_preference',
|
|
75
|
+
maxDelete: 1000,
|
|
76
|
+
dryRun: false,
|
|
77
|
+
dbPath: '/path/to/memory.db',
|
|
78
|
+
workspaceDir: '/path/to/workspace',
|
|
79
|
+
rootDir: '/path/to/workspace',
|
|
80
|
+
locale: 'en-US',
|
|
81
|
+
remote: false,
|
|
82
|
+
},
|
|
83
|
+
{ agentId: 'agent-1', isTrustedLocal: true },
|
|
84
|
+
);
|
|
85
|
+
```
|
|
25
86
|
|
|
26
|
-
|
|
27
|
-
const manager = await MemoryIndexManager.get({
|
|
28
|
-
workspaceDir: '/path/to/workspace',
|
|
29
|
-
});
|
|
87
|
+
### KG scope 三档
|
|
30
88
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
minScore: 0.5,
|
|
35
|
-
});
|
|
89
|
+
```typescript
|
|
90
|
+
// 只看本 Agent 节点(默认;MCP 入口强制)
|
|
91
|
+
await executeOp('graph_query', { agentId: 'agent-1', kind: 'nodes', scope: 'agent_only' }, { agentId: 'agent-1', isTrustedLocal: true });
|
|
36
92
|
|
|
37
|
-
//
|
|
38
|
-
await
|
|
93
|
+
// 只看共享节点
|
|
94
|
+
await executeOp('graph_query', { agentId: 'agent-1', kind: 'nodes', scope: 'shared_only' }, { agentId: 'agent-1', isTrustedLocal: true });
|
|
95
|
+
|
|
96
|
+
// 本 Agent + 共享(trusted local only;MCP 入口会拒绝)
|
|
97
|
+
await executeOp('graph_query', { agentId: 'agent-1', kind: 'nodes', scope: 'both' }, { agentId: 'agent-1', isTrustedLocal: true });
|
|
39
98
|
```
|
|
40
99
|
|
|
41
|
-
|
|
100
|
+
### Markdown 渲染
|
|
42
101
|
|
|
43
|
-
|
|
102
|
+
```typescript
|
|
103
|
+
import { renderOperationMarkdown } from '@easbot/memory';
|
|
104
|
+
const md = await renderOperationMarkdown('recall', recallResult, { toolName: 'memory_recall' });
|
|
105
|
+
```
|
|
44
106
|
|
|
45
|
-
|
|
46
|
-
|------|------|
|
|
47
|
-
| `get(params)` | 获取或创建管理器实例 |
|
|
48
|
-
| `search(query, options)` | 混合搜索 |
|
|
49
|
-
| `indexFile(filePath)` | 索引单个文件 |
|
|
50
|
-
| `indexDirectory(dirPath)` | 索引目录 |
|
|
51
|
-
| `getStatus()` | 获取状态信息 |
|
|
107
|
+
## 9 op 清单
|
|
52
108
|
|
|
53
|
-
|
|
109
|
+
| op | trusted local only | requires agentId | 用途 |
|
|
110
|
+
|---|---|---|---|
|
|
111
|
+
| `recall` | ❌ | ✅ | 混合搜索(FTS + vector + graph) |
|
|
112
|
+
| `remember` | ❌ | ✅ | 持久化一条 self-memory fact |
|
|
113
|
+
| `forget` | ❌ | ✅ | 按 factId / category / 时间窗删除(支持 `dryRun`) |
|
|
114
|
+
| `extract` | ❌ | ✅ | 从 session 抽取 facts |
|
|
115
|
+
| `consolidate` | ✅ | ✅ | 整理 / 去重 / 摘要 |
|
|
116
|
+
| `graph_query` | ❌ (scope=both 时 ✅) | ✅ | KG 节点 / 边 / 邻居查询 |
|
|
117
|
+
| `status` | ❌ | ⚠️ optional | 系统状态快照 |
|
|
118
|
+
| `doctor` | ✅ | ⚠️ optional | 数据完整性检查(支持 `repair`) |
|
|
119
|
+
| `init` | ✅ | ⚠️ optional | 初始化 workspace(支持 `force`) |
|
|
120
|
+
|
|
121
|
+
## API 分类
|
|
122
|
+
|
|
123
|
+
### services(9 op 业务层)
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
import { recall, remember, forget } from '@easbot/memory/services';
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### operations(9 op 注册表 + executeOp)
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
import { executeOp, OP_REGISTRY, ALL_OPS } from '@easbot/memory/operations';
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### format(schema + markdown + text + truncate + render)
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
import { renderOperationMarkdown } from '@easbot/memory/format/render';
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### hooks(4 hook 类型)
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
import type { PreCompactHook, SessionStartHook, SessionEndHook, PostToolFailureHook } from '@easbot/memory/hooks';
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## CLI / MCP 双入口(v0.4 stage 4 落地)
|
|
148
|
+
|
|
149
|
+
### 独立 CLI(`easbot-memory`)
|
|
54
150
|
|
|
55
151
|
```bash
|
|
56
|
-
#
|
|
57
|
-
|
|
152
|
+
# 安装后即可用(package.json bin: easbot-memory)
|
|
153
|
+
easbot-memory init --workspace-dir <dir>
|
|
154
|
+
easbot-memory status [--agent <id>] [--json]
|
|
155
|
+
easbot-memory doctor [--repair]
|
|
156
|
+
easbot-memory recall --query <q> [--agent <id>] [--limit <n>] [--json]
|
|
157
|
+
easbot-memory remember --content <text> --category <c> --importance <1-10>
|
|
158
|
+
easbot-memory forget [--agent <id>] [--fact-id <id>] [--dry-run]
|
|
159
|
+
easbot-memory extract --session <sessionId> [--last-n <n>]
|
|
160
|
+
easbot-memory consolidate [--agent <id>] [--window-days <n>]
|
|
161
|
+
easbot-memory graph --kind <nodes|edges|neighbors> [--query <q>]
|
|
162
|
+
easbot-memory config [--json]
|
|
163
|
+
easbot-memory mcp
|
|
164
|
+
```
|
|
58
165
|
|
|
59
|
-
|
|
60
|
-
pnpm build
|
|
166
|
+
### Agent 委派模式(v0.4 stage 4 T-M017a)
|
|
61
167
|
|
|
62
|
-
|
|
63
|
-
|
|
168
|
+
```bash
|
|
169
|
+
# @easbot/agent 的 memory 子命令直接委派 handleMemoryCli(决策 0049)
|
|
170
|
+
easbot memory recall --query "user preference"
|
|
171
|
+
easbot memory remember --content "老侯 prefers TypeScript"
|
|
172
|
+
easbot memory mcp # 启动 MCP stdio server
|
|
173
|
+
```
|
|
64
174
|
|
|
65
|
-
|
|
66
|
-
|
|
175
|
+
### MCP stdio server(v0.4 stage 4 T-M013abc)
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
import { MemoryStdioServer } from '@easbot/memory';
|
|
179
|
+
|
|
180
|
+
// 启动 9 tool 的 MCP stdio server(Cline / Claude Code / Continue 可调用)
|
|
181
|
+
// v0.4.0:start 签名简化(不需要 `memorySystem` 参数,handler 走 executeOp 调度 services)
|
|
182
|
+
await MemoryStdioServer.start({
|
|
183
|
+
name: 'easbot-memory',
|
|
184
|
+
version: '0.4.0',
|
|
185
|
+
description: 'EASBot memory MCP server',
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// 列出 9 个 tool 名
|
|
189
|
+
const tools = MemoryStdioServer.getToolNames();
|
|
190
|
+
// ['memory_recall', 'memory_remember', 'memory_forget', ...]
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
**9 tool 清单**(与 `OP_REGISTRY` 一一对应):
|
|
194
|
+
- `memory_recall` / `memory_remember` / `memory_forget` / `memory_extract` / `memory_consolidate` / `memory_graph_query` / `memory_status` / `memory_doctor` / `memory_init`
|
|
195
|
+
|
|
196
|
+
### handleMemoryCli 委派范式
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
import { handleMemoryCli, setGlobalAdapter, setInstanceAdapter } from '@easbot/memory';
|
|
200
|
+
|
|
201
|
+
// 1. 注入 adapter(cli 路径 / agent 路径)
|
|
202
|
+
setGlobalAdapter({ Path: { /* ... */ } });
|
|
203
|
+
setInstanceAdapter({ directory: process.cwd(), worktree: process.cwd() });
|
|
204
|
+
|
|
205
|
+
// 2. 委派给统一 handler
|
|
206
|
+
const result = await handleMemoryCli(['recall', '--query', 'test'], {
|
|
207
|
+
version: '0.4.0',
|
|
208
|
+
cwd: process.cwd(),
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
if (result.code !== 0) process.exit(result.code);
|
|
67
212
|
```
|
|
68
213
|
|
|
69
214
|
## 数据库位置
|
|
@@ -74,6 +219,36 @@ pnpm type-check
|
|
|
74
219
|
- macOS: `~/Library/Application Support/easbot/memory.db`
|
|
75
220
|
- Windows: `%APPDATA%/easbot/memory.db`
|
|
76
221
|
|
|
222
|
+
## 决策与迁移
|
|
223
|
+
|
|
224
|
+
- ADR 0055 / 0056 / 0057(v0.4 决策):`.easbot/protocol.json` 与 `docs/decisions/00NN-*.md`
|
|
225
|
+
- 迁移脚本:`scripts/migrate/{scan,apply,review}.ts` + `scripts/db-backup.ts`(v0.3 → v0.4 `owner_agent_id` 列添加 + 默认 scope = agent_only)
|
|
226
|
+
- CI guard(v0.4 stage 5 三包统一后台支撑):
|
|
227
|
+
- `scripts/check-database-facade.sh`(禁止直接 require better-sqlite3 / node:sqlite / createRequire)
|
|
228
|
+
- `scripts/check-mcp-facade.sh`(禁止直接 import @modelcontextprotocol/sdk)
|
|
229
|
+
- `scripts/check-terminal-facade.sh`(CLI 输出走 @easbot/terminal + COMMANDS_HELP 单一数据源)
|
|
230
|
+
- `scripts/check-cmd-i18n-coverage.sh`(zh-CN / en-US 双 locale 一致性 + switch-case 路由校验)
|
|
231
|
+
- L-M13 / L-M14 / L-M15 教训沉淀:`.easbot/knowledge/tasks/memory-v04-refactor/findings.md`
|
|
232
|
+
|
|
233
|
+
## 开发
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
# 安装
|
|
237
|
+
pnpm install
|
|
238
|
+
|
|
239
|
+
# 构建
|
|
240
|
+
pnpm build
|
|
241
|
+
|
|
242
|
+
# 测试(vitest 4)
|
|
243
|
+
pnpm test:run
|
|
244
|
+
|
|
245
|
+
# 类型检查
|
|
246
|
+
pnpm type-check
|
|
247
|
+
|
|
248
|
+
# lint(biome 2.x)
|
|
249
|
+
pnpm biome-lint
|
|
250
|
+
```
|
|
251
|
+
|
|
77
252
|
## 许可证
|
|
78
253
|
|
|
79
|
-
MIT
|
|
254
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var os=require('os'),path=require('path'),xdgBasedir=require('xdg-basedir');var r=null,n=null;function d(t){r=t;}function f(){r=null;}function s(){if(r)return r;let t=os.homedir();return {Path:{home:t,data:process.env.EASBOT_DATA_PATH?.trim()||path.join(xdgBasedir.xdgData??path.join(t,".local","share"),"easbot"),config:process.env.EASBOT_CONFIG_PATH?.trim()||path.join(t,".config","easbot"),state:process.env.EASBOT_STATE_PATH?.trim()||path.join(xdgBasedir.xdgData??path.join(t,".local","share"),"easbot","state"),cache:process.env.EASBOT_CACHE_PATH?.trim()||path.join(t,".cache","easbot"),log:process.env.EASBOT_LOG_PATH?.trim()||path.join(xdgBasedir.xdgData??path.join(t,".local","share"),"easbot","log"),bin:process.env.EASBOT_BIN_PATH?.trim()||path.join(t,".local","bin")}}}function A(t){n=t;}function I(){n=null;}function g(){if(n)return n;let t=process.cwd();return {directory:t,worktree:t}}function l(){return s().Path.home||os.homedir()}function c(){let t=s().Path.data;return t||(xdgBasedir.xdgData??path.join(l(),".local","share"))}function i(){return path.join(c(),"memory")}function T(){return path.join(i(),"memory.db")}exports.a=d;exports.b=f;exports.c=s;exports.d=A;exports.e=I;exports.f=g;exports.g=l;exports.h=c;exports.i=i;exports.j=T;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {b}from'./chunk-WQGSYA5D.mjs';import {Log,Filesystem}from'@easbot/utils';import {createSyncSqliteConnection}from'@easbot/database';var d=Log.create({service:"memory-schema-migrations"}),T=2,S=[{id:1,description:"v1 baseline: memory_facts / memory_vectors / embedding_cache / memory_facts_fts / nodes / edges / meta\uFF08\u4E0E v0.3.x createTables \u8F93\u51FA\u5BF9\u9F50\uFF0C\u8001 db \u8DD1\u8BE5\u8FC1\u79FB\u4E0D\u7834\u574F\u73B0\u6709\u8868\uFF09",up:[`CREATE TABLE IF NOT EXISTS memory_facts (
|
|
2
|
+
id TEXT PRIMARY KEY,
|
|
3
|
+
agent_id TEXT NOT NULL,
|
|
4
|
+
session_id TEXT,
|
|
5
|
+
msg_id TEXT,
|
|
6
|
+
parent_msg_id TEXT,
|
|
7
|
+
content TEXT NOT NULL,
|
|
8
|
+
category TEXT NOT NULL,
|
|
9
|
+
importance INTEGER NOT NULL CHECK(importance >= 1 AND importance <= 10),
|
|
10
|
+
source TEXT NOT NULL CHECK(source IN ('session_self_write', 'historical')),
|
|
11
|
+
tags TEXT,
|
|
12
|
+
node_ids TEXT,
|
|
13
|
+
file_path TEXT,
|
|
14
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
15
|
+
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
16
|
+
UNIQUE(session_id, msg_id)
|
|
17
|
+
)`,"CREATE INDEX IF NOT EXISTS idx_memory_facts_agent_id ON memory_facts(agent_id)","CREATE INDEX IF NOT EXISTS idx_memory_facts_agent_category ON memory_facts(agent_id, category)","CREATE INDEX IF NOT EXISTS idx_memory_facts_agent_importance ON memory_facts(agent_id, importance DESC)","CREATE INDEX IF NOT EXISTS idx_memory_facts_created_at ON memory_facts(created_at)",`CREATE TABLE IF NOT EXISTS memory_vectors (
|
|
18
|
+
fact_id TEXT PRIMARY KEY,
|
|
19
|
+
embedding BLOB NOT NULL,
|
|
20
|
+
FOREIGN KEY (fact_id) REFERENCES memory_facts(id) ON DELETE CASCADE
|
|
21
|
+
)`,`CREATE TABLE IF NOT EXISTS embedding_cache (
|
|
22
|
+
content_hash TEXT PRIMARY KEY,
|
|
23
|
+
embedding BLOB NOT NULL,
|
|
24
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
25
|
+
)`,`CREATE VIRTUAL TABLE IF NOT EXISTS memory_facts_fts USING fts5(
|
|
26
|
+
fact_id UNINDEXED,
|
|
27
|
+
agent_id UNINDEXED,
|
|
28
|
+
content,
|
|
29
|
+
tags,
|
|
30
|
+
tokenize='porter unicode61'
|
|
31
|
+
)`,`CREATE TABLE IF NOT EXISTS nodes (
|
|
32
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
33
|
+
name TEXT NOT NULL,
|
|
34
|
+
type TEXT NOT NULL,
|
|
35
|
+
properties TEXT,
|
|
36
|
+
createdAt DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
37
|
+
updatedAt DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
38
|
+
)`,"CREATE INDEX IF NOT EXISTS idx_nodes_name ON nodes(name)","CREATE INDEX IF NOT EXISTS idx_nodes_type ON nodes(type)","CREATE UNIQUE INDEX IF NOT EXISTS idx_nodes_name_type ON nodes(name, type)",`CREATE TABLE IF NOT EXISTS edges (
|
|
39
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
40
|
+
source INTEGER NOT NULL,
|
|
41
|
+
target INTEGER NOT NULL,
|
|
42
|
+
relation TEXT NOT NULL,
|
|
43
|
+
properties TEXT,
|
|
44
|
+
createdAt DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
45
|
+
FOREIGN KEY (source) REFERENCES nodes(id) ON DELETE CASCADE,
|
|
46
|
+
FOREIGN KEY (target) REFERENCES nodes(id) ON DELETE CASCADE
|
|
47
|
+
)`,"CREATE INDEX IF NOT EXISTS idx_edges_source ON edges(source)","CREATE INDEX IF NOT EXISTS idx_edges_target ON edges(target)","CREATE INDEX IF NOT EXISTS idx_edges_relation ON edges(relation)","CREATE UNIQUE INDEX IF NOT EXISTS idx_edges_unique ON edges(source, target, relation)",`CREATE TABLE IF NOT EXISTS meta (
|
|
48
|
+
key TEXT PRIMARY KEY,
|
|
49
|
+
value TEXT
|
|
50
|
+
)`]},{id:2,description:"v2: \u7ED9 nodes \u8868\u52A0 owner_agent_id \u5217 + \u7D22\u5F15\uFF08ADR 0056 KG scope \u4E09\u6863\uFF0Cper-agent \u9694\u79BB\uFF09",up:["ALTER TABLE nodes ADD COLUMN owner_agent_id TEXT","CREATE INDEX IF NOT EXISTS idx_nodes_owner_agent_id ON nodes(owner_agent_id)"]}];function m(n,e=T,t={}){n.exec(`CREATE TABLE IF NOT EXISTS schema_migrations (
|
|
51
|
+
id INTEGER PRIMARY KEY,
|
|
52
|
+
applied_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
53
|
+
)`);let i=n.prepare("SELECT id FROM schema_migrations").all(),a=new Set(i.map(r=>r.id)),s={applied:[],pending:[],errors:[],currentVersion:i.length===0?0:Math.max(...i.map(r=>r.id)),targetVersion:e};for(let r of S){if(r.id>e)break;if(a.has(r.id)){s.pending.push(r.id);continue}if(t.dryRun){s.applied.push(r.id);continue}try{_(n,r.up),n.prepare("INSERT INTO schema_migrations (id) VALUES (?)").run(r.id),a.add(r.id),s.applied.push(r.id),d.info("migration applied",{id:r.id,description:r.description});}catch(E){let l=E instanceof Error?E.message:String(E),h=r.up[0]??"";s.errors.push({migrationId:r.id,sql:h,error:l}),d.warn("migration step failed",{id:r.id,error:l,sqlCount:r.up.length});}}return s}function _(n,e){for(let t of e)try{n.exec(t);}catch(i){let a=i instanceof Error?i.message:String(i);if(R(a)){d.debug("migration: column already exists, skipping",{sql:t.slice(0,80)});continue}throw i}}function R(n){return /duplicate column name/i.test(n)}function g(n){try{let e=n.prepare("SELECT id FROM schema_migrations").all();return e.length===0?0:Math.max(...e.map(t=>t.id))}catch{return 0}}var c=Log.create({service:"memory-database"}),p=class{constructor(e){b(this,"db",null);b(this,"storagePath");b(this,"backend","better-sqlite3");b(this,"initialized",false);b(this,"initPromise",null);this.storagePath=e===":memory:"?e:Filesystem.normalize(e);}async initialize(){if(!this.initialized){if(this.initPromise){await this.initPromise;return}this.initPromise=this.doInitialize();try{await this.initPromise,this.initialized=!0;}catch(e){try{this.db&&this.db.close();}catch{}throw this.db=null,this.initPromise=null,e}}}async doInitialize(){try{let e=this.openConnection();e.initialize(),this.db=e,this.applyPragmas(),this.runAllMigrations();}catch(e){let t=e instanceof Error?e.message:String(e);throw c.error("Database initialization failed",{error:t}),e}}openConnection(){return createSyncSqliteConnection({path:this.storagePath,backend:this.backend,walMode:true,foreignKeys:true,busyTimeoutMs:5e3})}applyPragmas(){if(this.db)try{this.db.pragma("synchronous = NORMAL"),this.db.pragma("cache_size = -64000"),this.db.pragma("temp_store = MEMORY"),this.db.pragma("foreign_keys = ON");}catch(e){c.warn("Failed to apply memory PRAGMAs",{error:String(e)});}}runAllMigrations(){if(!this.db)throw new Error("Database not initialized");let e=m(this.db,T);if(e.errors.length>0){let t=e.errors.map(i=>`migration ${i.migrationId}: ${i.error}`).join("; ");throw new Error(`Some migrations failed: ${t}`)}}query(e,t){if(!this.db)throw new Error("Database not initialized. Call initialize() first.");try{let i=this.db.prepare(e);return t?i.all(...t):i.all()}catch(i){throw new Error(`Query failed: ${i.message}`)}}run(e,t){if(!this.db)throw new Error("Database not initialized. Call initialize() first.");try{let i=this.db.prepare(e),a=t?i.run(...t):i.run();return {lastID:Number(a.lastInsertRowid),changes:a.changes}}catch(i){throw new Error(`Write failed: ${i.message}`)}}transaction(e){if(!this.db)throw new Error("Database not initialized. Call initialize() first.");return this.db.transaction(e)()}prepare(e){if(!this.db)throw new Error("Database not initialized. Call initialize() first.");return this.db.prepare(e)}exec(e){if(!this.db)throw new Error("Database not initialized. Call initialize() first.");this.db.exec(e);}getDb(){if(!this.db)throw new Error("Database not initialized. Call initialize() first.");return this.db}getPath(){return this.storagePath}getSchemaVersion(){if(!this.db)throw new Error("Database not initialized. Call initialize() first.");return g(this.db)}close(){if(this.db){try{this.db.close();}catch(e){c.warn("Failed to close memory database",{error:String(e)});}this.db=null,this.initialized=false,this.initPromise=null;}}healthCheck(){try{return this.db?(this.db.exec("SELECT 1"),!0):!1}catch{return false}}getMeta(e){if(!this.db)throw new Error("Database not initialized");return this.db.prepare("SELECT value FROM meta WHERE key = ?").get(e)?.value??null}setMeta(e,t){if(!this.db)throw new Error("Database not initialized");this.db.prepare("INSERT OR REPLACE INTO meta (key, value) VALUES (?, ?)").run(e,t);}};export{T as a,S as b,m as c,g as d,p as e};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var y={languages:[{value:"zh-CN",name:"\u7B80\u4F53\u4E2D\u6587",example:"\u4F60\u597D\uFF0CEASBOT\uFF01",supported:true},{value:"en-US",name:"English (United States)",example:"Hello, EASBOT!",supported:true}]};var b=y.languages,L=b.filter(e=>e.supported).map(e=>e.value),a={defaultLocale:"zh-CN",locales:L},m={},d=(e,t)=>{let r=m[e]||{translation:{}};return m[e]={translation:{...r.translation,...t.translation}},m[e]},p=(e=a.defaultLocale)=>(m[e]||d(e,{translation:{}}),{locale:e,resources:m[e]||{translation:{}}});var C={translation:{"cli.cmd.init.description":"\u521D\u59CB\u5316\u8BB0\u5FC6 workspace\uFF08.easbot/memory.db\uFF09","cli.cmd.recall.description":"\u6DF7\u5408\u641C\u7D22\uFF08FTS + \u5411\u91CF\uFF09\u67E5\u8BE2\u8BB0\u5FC6","cli.cmd.remember.description":"\u5199\u5165\u4E00\u6761\u65B0\u8BB0\u5FC6\uFF08\u81EA\u5E26 dedup + \u77E5\u8BC6\u56FE\u8C31\u62BD\u53D6\uFF09","cli.cmd.forget.description":"\u5220\u9664\u8BB0\u5FC6\uFF08factId / category / \u65F6\u95F4\u7A97 / \u8BD5\u8FD0\u884C\uFF09","cli.cmd.extract.description":"\u4ECE session \u62BD\u53D6 facts\uFF08sessionId + lastN\uFF09","cli.cmd.consolidate.description":"\u8FD0\u884C consolidation \u6D41\u6C34\u7EBF\uFF08extract \u2192 dedup \u2192 archive\uFF09","cli.cmd.graph.description":"\u77E5\u8BC6\u56FE\u8C31\u67E5\u8BE2\uFF08nodes / edges / neighbors\uFF0Cscope \u4E09\u6863\uFF09","cli.cmd.status.description":"\u663E\u793A\u8BB0\u5FC6\u72B6\u6001 / \u6570\u636E\u5E93\u7EDF\u8BA1 / \u5404\u7C7B\u522B\u8BA1\u6570","cli.cmd.doctor.description":"\u8FD0\u884C\u5065\u5EB7\u68C0\u67E5\uFF08\u540E\u7AEF / FTS / schema / \u9501\uFF09","cli.cmd.config.description":"\u67E5\u770B / \u6821\u9A8C\u8BB0\u5FC6\u914D\u7F6E\uFF08dry-read\uFF09","cli.cmd.mcp.description":"\u542F\u52A8 stdio MCP \u670D\u52A1\u5668\uFF08\u66B4\u9732 9 \u4E2A memory \u5DE5\u5177\uFF09","memory.recall.empty":"\uFF08\u65E0\u5339\u914D\u8BB0\u5FC6\uFF09","memory.recall.summary":"\u5171\u5339\u914D {total} \u6761\u8BB0\u5FC6\uFF1A","memory.recall.item":" - {id} [{category}/\u91CD\u8981\u6027={importance}/\u5206\u6570={score}] {content}","memory.forget.empty":"\uFF08\u672A\u547D\u4E2D\u53EF\u5220\u9664\u7684\u8BB0\u5F55\uFF09\uFF09","memory.forget.summary":"\u5220\u9664 {deletedCount} \u6761\u8BB0\u5FC6\uFF08dryRun={dryRun}\uFF09\uFF1A","memory.forget.item":" - {id}","memory.remember.summary":"\u8BB0\u5FC6\u5DF2\u5199\u5165\uFF1A","memory.remember.item":" - id={id} \u7C7B\u522B={category} \u91CD\u8981\u6027={importance}","memory.consolidate.summary":"consolidation \u5B8C\u6210\uFF1A","memory.consolidate.item":" - \u603B\u8BA1 {totalFacts} \u53BB\u91CD {dedupedCount} \u5F52\u6863 {archivedCount}","memory.status.empty":"\uFF08\u6682\u65E0\u6570\u636E\uFF09","memory.status.summary":"\u8BB0\u5FC6\u72B6\u6001\uFF1A","memory.status.item":" - {key}: {value}","memory.doctor.empty":"\uFF08\u65E0\u68C0\u67E5\u9879\uFF09","memory.doctor.summary":"\u5065\u5EB7\u68C0\u67E5\uFF1A{status}","memory.doctor.item":" - {name}: {message}","memory.graph.empty":"\uFF08\u65E0\u8282\u70B9\u547D\u4E2D\uFF09","memory.graph.summary":"\u77E5\u8BC6\u56FE\u8C31\u67E5\u8BE2\uFF08\u5171 {totalNodes} \u8282\u70B9\uFF09\uFF1A","memory.graph.item":" - {id} {name} [{type}]","memory.extract.summary":"\u62BD\u53D6 {extractedCount} \u6761 facts\uFF1A","memory.extract.item":" - {id}","memory.init.summary":"\u521D\u59CB\u5316\u5B8C\u6210\uFF1A","memory.init.item":" - db={dbPath} \u8FC1\u79FB={migrationsApplied} \u8868={tablesCreated}"}},f=C;var S={translation:{"cli.cmd.init.description":"Initialize memory workspace (.easbot/memory.db)","cli.cmd.recall.description":"Hybrid search (FTS + vector) over memory facts","cli.cmd.remember.description":"Persist a new memory fact (with dedup + KG extraction)","cli.cmd.forget.description":"Delete memory facts (factId / category / timeRange / dryRun)","cli.cmd.extract.description":"Extract facts from a session (sessionId + lastN)","cli.cmd.consolidate.description":"Run consolidation pipeline (extract \u2192 dedup \u2192 archive)","cli.cmd.graph.description":"KG query (nodes / edges / neighbors with scope \u4E09\u6863)","cli.cmd.status.description":"Show memory state / db stats / facts by category","cli.cmd.doctor.description":"Run health checks (backend, FTS, schema, lock)","cli.cmd.config.description":"Show / validate memory configuration (dry-read)","cli.cmd.mcp.description":"Start stdio MCP server (exposes 9 memory tools)","memory.recall.empty":"(no matching facts)","memory.recall.summary":"Found {total} fact(s):","memory.recall.item":" - {id} [{category}/imp={importance}/score={score}] {content}","memory.forget.empty":"(no records to delete)","memory.forget.summary":"Deleted {deletedCount} fact(s) (dryRun={dryRun}):","memory.forget.item":" - {id}","memory.remember.summary":"Memory persisted:","memory.remember.item":" - id={id} category={category} importance={importance}","memory.consolidate.summary":"Consolidation complete:","memory.consolidate.item":" - total {totalFacts} deduped {dedupedCount} archived {archivedCount}","memory.status.empty":"(no data)","memory.status.summary":"Memory status:","memory.status.item":" - {key}: {value}","memory.doctor.empty":"(no checks)","memory.doctor.summary":"Health check: {status}","memory.doctor.item":" - {name}: {message}","memory.graph.empty":"(no nodes matched)","memory.graph.summary":"KG query ({totalNodes} node(s)):","memory.graph.item":" - {id} {name} [{type}]","memory.extract.summary":"Extracted {extractedCount} fact(s):","memory.extract.item":" - {id}","memory.init.summary":"Initialization complete:","memory.init.item":" - db={dbPath} migrations={migrationsApplied} tables={tablesCreated}"}},h=S;var v=()=>{p("zh-CN"),p("en-US"),d("zh-CN",f),d("en-US",h);};v();var u=new Map;var g=new Map;var w=e=>{if(g.has(e))return g.get(e);let t=/{{\s*(\w+)\s*}}/g,r=[],o;for(;(o=t.exec(e))!==null;){let n=o[1];n&&!r.includes(n)&&r.push(n);}let i=new RegExp("{{\\s*("+r.join("|")+")\\s*}}","g"),s={keys:r,regex:i};return g.set(e,s),s},x=(e,t)=>{if(!e||typeof e!="string")return "";if(!t||Object.keys(t).length===0)return e;let{regex:r,keys:o}=w(e);return o.length===0||!o.some(s=>s in t)?e:e.replace(r,(s,n)=>{let c=t[n];return c==null?"":String(c)})},k=e=>{if(e&&a.locales.includes(e))return e;let t=process.env.EASBOT_LANG?.trim()||process.env.LANG?.trim();if(t){let r=t.replace(/_/g,"-");if(a.locales.includes(r))return r;let o=r.split("-")[0];if(o==="zh")return "zh-CN";if(o==="en")return "en-US"}return a.defaultLocale},R=e=>{if(!u.has(e)){let{resources:t}=p(e);u.set(e,t);}return u.get(e)},I=(e,t={})=>{let r=k(t.locale),i=R(r)?.translation[e];if(i&&typeof i=="string"){let s=x(i,t.vars);return s!=null?String(s):String(e)}if(r!==a.defaultLocale){let n=R(a.defaultLocale)?.translation[e];if(n&&typeof n=="string"){let c=x(n,t.vars);return c!=null?String(c):String(e)}}return String(t.fallback??e)},_=I;exports.a=_;
|