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 +315 -0
- package/bin/xmemory-cli.cjs +4382 -0
- package/bin/xmemory-cli.js +277 -0
- package/bin/xmemory-cli.mjs +4160 -0
- package/package.json +36 -0
- package/src/api/client.ts +144 -0
- package/src/commands/add.ts +36 -0
- package/src/commands/delete.ts +25 -0
- package/src/commands/get.ts +35 -0
- package/src/commands/graph.ts +90 -0
- package/src/commands/list.ts +36 -0
- package/src/commands/search.ts +46 -0
- package/src/commands/spaces.ts +88 -0
- package/src/commands/tags.ts +28 -0
- package/src/config/index.ts +179 -0
- package/src/index.ts +31 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { Command } = require("commander");
|
|
6
|
+
const { loadConfig, Client } = require("../src/index");
|
|
7
|
+
const { SearchCommand } = require("../src/commands/search");
|
|
8
|
+
const { AddCommand } = require("../src/commands/add");
|
|
9
|
+
const { ListCommand } = require("../src/commands/list");
|
|
10
|
+
const { DeleteCommand } = require("../src/commands/delete");
|
|
11
|
+
const { GetCommand } = require("../src/commands/get");
|
|
12
|
+
const { SpacesCommand } = require("../src/commands/spaces");
|
|
13
|
+
const { TagsCommand } = require("../src/commands/tags");
|
|
14
|
+
const { GraphCommand } = require("../src/commands/graph");
|
|
15
|
+
const { readFileSync } = require("fs");
|
|
16
|
+
const path = require("path");
|
|
17
|
+
|
|
18
|
+
const { version } = JSON.parse(
|
|
19
|
+
readFileSync(path.join(__dirname, "..", "package.json"), "utf-8"),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const program = new Command();
|
|
23
|
+
|
|
24
|
+
program
|
|
25
|
+
.name("xmemory-cli")
|
|
26
|
+
.description(
|
|
27
|
+
"xMemory CLI - Command-line interface for xMemory knowledge base",
|
|
28
|
+
)
|
|
29
|
+
.version(version)
|
|
30
|
+
.option("-c, --config <path>", "Path to config file")
|
|
31
|
+
.option("--api-base-url <url>", "API base URL", "http://localhost:50505/api")
|
|
32
|
+
.option("-s, --space <name>", "Default space name")
|
|
33
|
+
.option("--output <format>", "Output format: json or text", "text")
|
|
34
|
+
.hook("preAction", (thisCommand) => {
|
|
35
|
+
const opts = thisCommand.opts();
|
|
36
|
+
const config = loadConfig({
|
|
37
|
+
apiBaseUrl: opts.apiBaseUrl,
|
|
38
|
+
defaultSpace: opts.space,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
program.mockClient = new Client(config);
|
|
42
|
+
program.mockConfig = config;
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
program
|
|
46
|
+
.command("search <query>")
|
|
47
|
+
.description("Search memories by query")
|
|
48
|
+
.option("-l, --limit <number>", "Maximum number of results", "5")
|
|
49
|
+
.option("-s, --space <name>", "Filter by space")
|
|
50
|
+
.option("--json", "Output as JSON")
|
|
51
|
+
.action(async (query, opts) => {
|
|
52
|
+
const client = program.mockClient;
|
|
53
|
+
if (!client) {
|
|
54
|
+
console.error("Error: Client not initialized");
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
await SearchCommand(client, query, {
|
|
59
|
+
limit: parseInt(opts.limit),
|
|
60
|
+
space: opts.space,
|
|
61
|
+
json: opts.json,
|
|
62
|
+
});
|
|
63
|
+
} catch (err) {
|
|
64
|
+
console.error("Error:", err instanceof Error ? err.message : err);
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
program
|
|
70
|
+
.command("add <content>")
|
|
71
|
+
.description("Add a new memory")
|
|
72
|
+
.option("-s, --space <name>", "Space name")
|
|
73
|
+
.option("--space-id <id>", "Space ID")
|
|
74
|
+
.option("-t, --tags <tags...>", "Tags")
|
|
75
|
+
.option("--source <source>", "Source of the memory")
|
|
76
|
+
.option("--json", "Output as JSON")
|
|
77
|
+
.action(async (content, opts) => {
|
|
78
|
+
const client = program.mockClient;
|
|
79
|
+
if (!client) {
|
|
80
|
+
console.error("Error: Client not initialized");
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
await AddCommand(client, content, {
|
|
85
|
+
space: opts.space,
|
|
86
|
+
spaceId: opts.spaceId,
|
|
87
|
+
tags: opts.tags,
|
|
88
|
+
source: opts.source,
|
|
89
|
+
json: opts.json,
|
|
90
|
+
});
|
|
91
|
+
} catch (err) {
|
|
92
|
+
console.error("Error:", err instanceof Error ? err.message : err);
|
|
93
|
+
process.exit(1);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
program
|
|
98
|
+
.command("list")
|
|
99
|
+
.description("List memories")
|
|
100
|
+
.option("-s, --space <name>", "Space name to list memories from")
|
|
101
|
+
.option("--json", "Output as JSON")
|
|
102
|
+
.action(async (opts) => {
|
|
103
|
+
const client = program.mockClient;
|
|
104
|
+
if (!client) {
|
|
105
|
+
console.error("Error: Client not initialized");
|
|
106
|
+
process.exit(1);
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
await ListCommand(client, { space: opts.space, json: opts.json });
|
|
110
|
+
} catch (err) {
|
|
111
|
+
console.error("Error:", err instanceof Error ? err.message : err);
|
|
112
|
+
process.exit(1);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
program
|
|
117
|
+
.command("get <id>")
|
|
118
|
+
.description("Get a single memory by ID")
|
|
119
|
+
.option("--json", "Output as JSON")
|
|
120
|
+
.action(async (id, opts) => {
|
|
121
|
+
const client = program.mockClient;
|
|
122
|
+
if (!client) {
|
|
123
|
+
console.error("Error: Client not initialized");
|
|
124
|
+
process.exit(1);
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
await GetCommand(client, id, { json: opts.json });
|
|
128
|
+
} catch (err) {
|
|
129
|
+
console.error("Error:", err instanceof Error ? err.message : err);
|
|
130
|
+
process.exit(1);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
program
|
|
135
|
+
.command("delete <id>")
|
|
136
|
+
.description("Delete a memory by ID")
|
|
137
|
+
.option("--json", "Output as JSON")
|
|
138
|
+
.action(async (id, opts) => {
|
|
139
|
+
const client = program.mockClient;
|
|
140
|
+
if (!client) {
|
|
141
|
+
console.error("Error: Client not initialized");
|
|
142
|
+
process.exit(1);
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
await DeleteCommand(client, id, { json: opts.json });
|
|
146
|
+
} catch (err) {
|
|
147
|
+
console.error("Error:", err instanceof Error ? err.message : err);
|
|
148
|
+
process.exit(1);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const spacesCmd = program.command("spaces").description("Manage spaces");
|
|
153
|
+
|
|
154
|
+
spacesCmd
|
|
155
|
+
.command("list")
|
|
156
|
+
.description("List all spaces")
|
|
157
|
+
.option("--json", "Output as JSON")
|
|
158
|
+
.action(async (opts) => {
|
|
159
|
+
const client = program.mockClient;
|
|
160
|
+
if (!client) {
|
|
161
|
+
console.error("Error: Client not initialized");
|
|
162
|
+
process.exit(1);
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
await SpacesCommand(client, { action: "list", json: opts.json });
|
|
166
|
+
} catch (err) {
|
|
167
|
+
console.error("Error:", err instanceof Error ? err.message : err);
|
|
168
|
+
process.exit(1);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
spacesCmd
|
|
173
|
+
.command("create <name>")
|
|
174
|
+
.description("Create a new space")
|
|
175
|
+
.option("-d, --description <text>", "Space description")
|
|
176
|
+
.option("--json", "Output as JSON")
|
|
177
|
+
.action(async (name, opts) => {
|
|
178
|
+
const client = program.mockClient;
|
|
179
|
+
if (!client) {
|
|
180
|
+
console.error("Error: Client not initialized");
|
|
181
|
+
process.exit(1);
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
await SpacesCommand(client, {
|
|
185
|
+
action: "create",
|
|
186
|
+
name,
|
|
187
|
+
description: opts.description,
|
|
188
|
+
json: opts.json,
|
|
189
|
+
});
|
|
190
|
+
} catch (err) {
|
|
191
|
+
console.error("Error:", err instanceof Error ? err.message : err);
|
|
192
|
+
process.exit(1);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
spacesCmd
|
|
197
|
+
.command("delete <id>")
|
|
198
|
+
.description("Delete a space by ID")
|
|
199
|
+
.option("--json", "Output as JSON")
|
|
200
|
+
.action(async (id, opts) => {
|
|
201
|
+
const client = program.mockClient;
|
|
202
|
+
if (!client) {
|
|
203
|
+
console.error("Error: Client not initialized");
|
|
204
|
+
process.exit(1);
|
|
205
|
+
}
|
|
206
|
+
try {
|
|
207
|
+
await SpacesCommand(client, { action: "delete", id, json: opts.json });
|
|
208
|
+
} catch (err) {
|
|
209
|
+
console.error("Error:", err instanceof Error ? err.message : err);
|
|
210
|
+
process.exit(1);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
spacesCmd
|
|
215
|
+
.command("info <id>")
|
|
216
|
+
.description("Get space details by ID")
|
|
217
|
+
.option("--json", "Output as JSON")
|
|
218
|
+
.action(async (id, opts) => {
|
|
219
|
+
const client = program.mockClient;
|
|
220
|
+
if (!client) {
|
|
221
|
+
console.error("Error: Client not initialized");
|
|
222
|
+
process.exit(1);
|
|
223
|
+
}
|
|
224
|
+
try {
|
|
225
|
+
await SpacesCommand(client, { action: "info", id, json: opts.json });
|
|
226
|
+
} catch (err) {
|
|
227
|
+
console.error("Error:", err instanceof Error ? err.message : err);
|
|
228
|
+
process.exit(1);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
program
|
|
233
|
+
.command("tags")
|
|
234
|
+
.description("List popular tags")
|
|
235
|
+
.option("--space-id <id>", "Filter by space ID")
|
|
236
|
+
.option("--json", "Output as JSON")
|
|
237
|
+
.action(async (opts) => {
|
|
238
|
+
const client = program.mockClient;
|
|
239
|
+
if (!client) {
|
|
240
|
+
console.error("Error: Client not initialized");
|
|
241
|
+
process.exit(1);
|
|
242
|
+
}
|
|
243
|
+
try {
|
|
244
|
+
await TagsCommand(client, { spaceId: opts.spaceId, json: opts.json });
|
|
245
|
+
} catch (err) {
|
|
246
|
+
console.error("Error:", err instanceof Error ? err.message : err);
|
|
247
|
+
process.exit(1);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
program
|
|
252
|
+
.command("graph")
|
|
253
|
+
.description("Query the knowledge graph")
|
|
254
|
+
.option("-e, --entity <name>", "Entity name to look up")
|
|
255
|
+
.option("-t, --tag <tag>", "Filter by tag")
|
|
256
|
+
.option("--space-id <id>", "Filter by space ID")
|
|
257
|
+
.option("--json", "Output as JSON")
|
|
258
|
+
.action(async (opts) => {
|
|
259
|
+
const client = program.mockClient;
|
|
260
|
+
if (!client) {
|
|
261
|
+
console.error("Error: Client not initialized");
|
|
262
|
+
process.exit(1);
|
|
263
|
+
}
|
|
264
|
+
try {
|
|
265
|
+
await GraphCommand(client, {
|
|
266
|
+
entityName: opts.entity,
|
|
267
|
+
tag: opts.tag,
|
|
268
|
+
spaceId: opts.spaceId,
|
|
269
|
+
json: opts.json,
|
|
270
|
+
});
|
|
271
|
+
} catch (err) {
|
|
272
|
+
console.error("Error:", err instanceof Error ? err.message : err);
|
|
273
|
+
process.exit(1);
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
program.parse();
|