xmemory-cli 0.1.0

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.md ADDED
@@ -0,0 +1,315 @@
1
+ # xMemory CLI
2
+
3
+ xMemory 命令行工具 — 从终端访问和管理你的知识库。
4
+
5
+ ## 特性
6
+
7
+ - 🔍 **语义搜索** — 基于向量的记忆搜索
8
+ - 📝 **快速添加** — 命令行即时记录想法
9
+ - 🗂️ **空间管理** — 创建和管理多个工作空间
10
+ - 🏷️ **标签系统** — 按标签组织和筛选
11
+ - 🔗 **知识图谱** — 查询实体关系网络
12
+ - 📦 **多环境支持** — 项目级配置,互不干扰
13
+
14
+ ## 安装
15
+
16
+ ### 方式一:npm 全局安装
17
+
18
+ ```bash
19
+ npm install -g @xmemory/cli
20
+ ```
21
+
22
+ ### 方式二:从源码构建
23
+
24
+ ```bash
25
+ cd packages/xmemory-cli
26
+ pnpm install
27
+ pnpm run build
28
+ pnpm link --global # 或手动链接到 PATH
29
+ ```
30
+
31
+ ### 方式三:直接运行(无需安装)
32
+
33
+ ```bash
34
+ cd packages/xmemory-cli
35
+ pnpm install
36
+ node bin/xmemory-cli.cjs --help
37
+ ```
38
+
39
+ ## 快速开始
40
+
41
+ ### 1. 配置 API Key
42
+
43
+ > **⚠️ 安全警告:** API Key 明文存储在配置文件中。请确保 `.xmemory.json` 文件权限为 600(`chmod 600 ~/.xmemory.json`),不要将其提交到代码仓库。
44
+
45
+ **推荐方式:环境变量**
46
+
47
+ ```bash
48
+ export XMEMORY_API_KEY="xm-your-api-key-here"
49
+ export DEFAULT_SPACE="my-workspace"
50
+ ```
51
+
52
+ **备选:配置文件**
53
+
54
+ 在项目根目录或 home 目录创建 `.xmemory.json`:
55
+
56
+ ```json
57
+ {
58
+ "apiBaseUrl": "http://localhost:50505/api",
59
+ "defaultSpace": "my-workspace",
60
+ "apiKey": "xm-your-api-key-here"
61
+ }
62
+ ```
63
+
64
+ 或设置环境变量:
65
+
66
+ ```bash
67
+ export XMEMORY_API_KEY="xm-your-api-key"
68
+ export DEFAULT_SPACE="my-workspace"
69
+ ```
70
+
71
+ ### 2. 获取 API Key
72
+
73
+ 1. 启动 xMemory:`bun run start:web`
74
+ 2. 访问 http://localhost:50505/settings
75
+ 3. 进入 **Developer** → **Generate API Key**
76
+
77
+ ### 3. 开始使用
78
+
79
+ ```bash
80
+ # 搜索记忆
81
+ xmemory-cli search "Next.js 路由"
82
+
83
+ # 添加记忆
84
+ xmemory-cli add "记住:明天开会"
85
+
86
+ # 列出所有空间
87
+ xmemory-cli spaces list
88
+
89
+ # 查询知识图谱
90
+ xmemory-cli graph --entity "Elon Musk"
91
+ ```
92
+
93
+ ## 命令
94
+
95
+ ### search — 搜索记忆
96
+
97
+ ```bash
98
+ xmemory-cli search <query> [options]
99
+ ```
100
+
101
+ | 选项 | 说明 |
102
+ | -------------------- | -------------------- |
103
+ | `-l, --limit <n>` | 最大结果数(默认 5) |
104
+ | `-s, --space <name>` | 按空间筛选 |
105
+ | `--json` | JSON 格式输出 |
106
+
107
+ ### add — 添加记忆
108
+
109
+ ```bash
110
+ xmemory-cli add <content> [options]
111
+ ```
112
+
113
+ | 选项 | 说明 |
114
+ | ---------------------- | -------------- |
115
+ | `-s, --space <name>` | 空间名称 |
116
+ | `--space-id <id>` | 空间 ID |
117
+ | `-t, --tags <tags...>` | 标签 |
118
+ | `--source <source>` | 来源(如 URL) |
119
+ | `--json` | JSON 格式输出 |
120
+
121
+ ### list — 列出空间
122
+
123
+ ```bash
124
+ xmemory-cli list [options]
125
+ ```
126
+
127
+ | 选项 | 说明 |
128
+ | -------------------- | ------------------ |
129
+ | `-s, --space <name>` | 列出指定空间的记忆 |
130
+ | `--json` | JSON 格式输出 |
131
+
132
+ ### get — 获取单条记忆
133
+
134
+ ```bash
135
+ xmemory-cli get <id> [options]
136
+ ```
137
+
138
+ | 选项 | 说明 |
139
+ | -------- | ------------- |
140
+ | `--json` | JSON 格式输出 |
141
+
142
+ ### delete — 删除记忆
143
+
144
+ ```bash
145
+ xmemory-cli delete <id> [options]
146
+ ```
147
+
148
+ | 选项 | 说明 |
149
+ | -------- | ------------- |
150
+ | `--json` | JSON 格式输出 |
151
+
152
+ ### spaces — 空间管理
153
+
154
+ ```bash
155
+ xmemory-cli spaces <action> [options]
156
+ ```
157
+
158
+ 动作:
159
+
160
+ | 动作 | 说明 |
161
+ | --------------- | ------------ |
162
+ | `list` | 列出所有空间 |
163
+ | `create <name>` | 创建空间 |
164
+ | `delete <id>` | 删除空间 |
165
+ | `info <id>` | 空间详情 |
166
+
167
+ 选项:
168
+
169
+ | 选项 | 适用动作 | 说明 |
170
+ | -------------------------- | -------- | ------------- |
171
+ | `-d, --description <text>` | create | 空间描述 |
172
+ | `--json` | 全部 | JSON 格式输出 |
173
+
174
+ ### tags — 标签列表
175
+
176
+ ```bash
177
+ xmemory-cli tags [options]
178
+ ```
179
+
180
+ | 选项 | 说明 |
181
+ | ----------------- | ------------- |
182
+ | `--space-id <id>` | 按空间筛选 |
183
+ | `--json` | JSON 格式输出 |
184
+
185
+ ### graph — 知识图谱
186
+
187
+ ```bash
188
+ xmemory-cli graph [options]
189
+ ```
190
+
191
+ | 选项 | 说明 |
192
+ | --------------------- | ------------- |
193
+ | `-e, --entity <name>` | 查询实体 |
194
+ | `-t, --tag <tag>` | 按标签筛选 |
195
+ | `--space-id <id>` | 按空间筛选 |
196
+ | `--json` | JSON 格式输出 |
197
+
198
+ ## 全局选项
199
+
200
+ | 选项 | 说明 |
201
+ | ---------------------- | ---------------------- |
202
+ | `-c, --config <path>` | 配置文件路径 |
203
+ | `--api-base-url <url>` | API 地址 |
204
+ | `-s, --space <name>` | 默认空间 |
205
+ | `--output <format>` | 输出格式:json 或 text |
206
+
207
+ ## 多项目管理
208
+
209
+ ### 项目级配置
210
+
211
+ 每个项目可以有独立的配置:
212
+
213
+ ```bash
214
+ ~/projects/project-a/.xmemory.json # 项目 A 配置
215
+ ~/projects/project-b/.xmemory.json # 项目 B 配置
216
+ ```
217
+
218
+ CLI 会自动读取当前目录下的配置:
219
+
220
+ ```bash
221
+ cd ~/projects/project-a
222
+ xmemory-cli search "query" # 使用 project-a 的配置
223
+
224
+ cd ~/projects/project-b
225
+ xmemory-cli search "query" # 使用 project-b 的配置
226
+ ```
227
+
228
+ ### 指定配置文件
229
+
230
+ ```bash
231
+ xmemory-cli search "query" --config ~/configs/prod.json
232
+ ```
233
+
234
+ ### Shell 别名
235
+
236
+ ```bash
237
+ # ~/.bashrc 或 ~/.zshrc
238
+ alias xm-a='xmemory-cli --config ~/.xmemory-project-a.json'
239
+ alias xm-b='xmemory-cli --config ~/.xmemory-project-b.json'
240
+ ```
241
+
242
+ ## 输出示例
243
+
244
+ ### 文本模式(默认)
245
+
246
+ ```
247
+ $ xmemory-cli search "Next.js"
248
+
249
+ Found 3 memories:
250
+
251
+ [abc123] (92.1% match)
252
+ Next.js App Router 使用 Server Components 作为默认渲染方式...
253
+ Tags: nextjs, react
254
+ Created: 2024-01-15 10:30:00
255
+
256
+ [def456] (85.3% match)
257
+ Next.js 14 新特性:Server Actions 和 Route Handlers...
258
+ Tags: nextjs
259
+ Created: 2024-01-14 15:20:00
260
+ ```
261
+
262
+ ### JSON 模式
263
+
264
+ ```bash
265
+ xmemory-cli search "Next.js" --json
266
+ ```
267
+
268
+ ```json
269
+ {
270
+ "results": [
271
+ {
272
+ "id": "abc123",
273
+ "content": "Next.js App Router 使用 Server Components...",
274
+ "tags": ["nextjs", "react"],
275
+ "similarity": 0.921,
276
+ "createdAt": "2024-01-15T10:30:00Z"
277
+ }
278
+ ]
279
+ }
280
+ ```
281
+
282
+ ## 项目结构
283
+
284
+ ```
285
+ packages/xmemory-cli/
286
+ ├── package.json
287
+ ├── build.mjs # esbuild 构建脚本
288
+ ├── bin/
289
+ │ ├── xmemory-cli.js # 源码入口
290
+ │ └── xmemory-cli.cjs # 构建产物
291
+ └── src/
292
+ ├── index.ts # 包导出
293
+ ├── config/index.ts # 配置加载
294
+ ├── api/client.ts # API 客户端
295
+ └── commands/
296
+ ├── search.ts
297
+ ├── add.ts
298
+ ├── list.ts
299
+ ├── get.ts
300
+ ├── delete.ts
301
+ ├── spaces.ts
302
+ ├── tags.ts
303
+ └── graph.ts
304
+ ```
305
+
306
+ ## 技术栈
307
+
308
+ - **运行时**:Node.js >= 18
309
+ - **打包**:esbuild
310
+ - **CLI 框架**:Commander.js
311
+ - **输出着色**:Chalk
312
+
313
+ ## 许可证
314
+
315
+ MIT