@mem0/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/dist/index.js ADDED
@@ -0,0 +1,523 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ getBackend
4
+ } from "./chunk-O3XZVUUX.js";
5
+ import {
6
+ loadConfig
7
+ } from "./chunk-EJ5AQPMT.js";
8
+ import {
9
+ colors,
10
+ printError
11
+ } from "./chunk-I7ABQZUR.js";
12
+
13
+ // src/index.ts
14
+ import fs from "fs";
15
+ import path from "path";
16
+ import { fileURLToPath } from "url";
17
+ import { createRequire } from "module";
18
+ import { Command } from "commander";
19
+
20
+ // src/help.ts
21
+ import chalk from "chalk";
22
+ var cyanBold = chalk.cyan.bold;
23
+ var greenBold = chalk.green.bold;
24
+ var yellowBold = chalk.yellow.bold;
25
+ var yellow = chalk.yellow;
26
+ var bold = chalk.bold;
27
+ var dim = chalk.dim;
28
+ var dimBorder = chalk.dim;
29
+ var ANSI_RE = /\x1b\[[0-9;]*m/g;
30
+ function stripAnsi(str) {
31
+ return str.replace(ANSI_RE, "").length;
32
+ }
33
+ var COMMAND_GROUPS = [
34
+ {
35
+ panel: "Memory",
36
+ commands: ["add", "search", "get", "list", "update", "delete"]
37
+ },
38
+ {
39
+ panel: "Management",
40
+ commands: ["init", "status", "import", "help", "entity", "config"]
41
+ }
42
+ ];
43
+ var COMMAND_ORDER = COMMAND_GROUPS.flatMap((g) => g.commands);
44
+ var OPTION_PANELS = {
45
+ add: {
46
+ "--user-id": "Scope",
47
+ "--agent-id": "Scope",
48
+ "--app-id": "Scope",
49
+ "--run-id": "Scope",
50
+ "--output": "Output",
51
+ "--api-key": "Connection",
52
+ "--base-url": "Connection"
53
+ },
54
+ search: {
55
+ "--user-id": "Scope",
56
+ "--agent-id": "Scope",
57
+ "--app-id": "Scope",
58
+ "--run-id": "Scope",
59
+ "--top-k": "Search",
60
+ "--threshold": "Search",
61
+ "--rerank": "Search",
62
+ "--keyword": "Search",
63
+ "--filter": "Search",
64
+ "--fields": "Search",
65
+ "--graph": "Search",
66
+ "--no-graph": "Search",
67
+ "--output": "Output",
68
+ "--api-key": "Connection",
69
+ "--base-url": "Connection"
70
+ },
71
+ get: {
72
+ "--output": "Output",
73
+ "--api-key": "Connection",
74
+ "--base-url": "Connection"
75
+ },
76
+ list: {
77
+ "--user-id": "Scope",
78
+ "--agent-id": "Scope",
79
+ "--app-id": "Scope",
80
+ "--run-id": "Scope",
81
+ "--page": "Pagination",
82
+ "--page-size": "Pagination",
83
+ "--category": "Filters",
84
+ "--after": "Filters",
85
+ "--before": "Filters",
86
+ "--graph": "Filters",
87
+ "--no-graph": "Filters",
88
+ "--output": "Output",
89
+ "--api-key": "Connection",
90
+ "--base-url": "Connection"
91
+ },
92
+ update: {
93
+ "--output": "Output",
94
+ "--api-key": "Connection",
95
+ "--base-url": "Connection"
96
+ },
97
+ delete: {
98
+ "--user-id": "Scope",
99
+ "--agent-id": "Scope",
100
+ "--app-id": "Scope",
101
+ "--run-id": "Scope",
102
+ "--output": "Output",
103
+ "--api-key": "Connection",
104
+ "--base-url": "Connection"
105
+ },
106
+ status: {
107
+ "--output": "Output",
108
+ "--api-key": "Connection",
109
+ "--base-url": "Connection"
110
+ },
111
+ import: {
112
+ "--user-id": "Scope",
113
+ "--agent-id": "Scope",
114
+ "--output": "Output",
115
+ "--api-key": "Connection",
116
+ "--base-url": "Connection"
117
+ }
118
+ };
119
+ var PANEL_ORDER = [
120
+ "Scope",
121
+ "Search",
122
+ "Pagination",
123
+ "Filters",
124
+ "Output",
125
+ "Connection"
126
+ ];
127
+ function renderPanel(title, rows, width) {
128
+ if (rows.length === 0) return "";
129
+ const inner = width - 2;
130
+ const titleStr = ` ${title} `;
131
+ const fillLen = Math.max(0, inner - 1 - titleStr.length);
132
+ const topLine = dimBorder("\u256D\u2500") + dimBorder(titleStr) + dimBorder("\u2500".repeat(fillLen)) + dimBorder("\u256E");
133
+ const bottomLine = dimBorder("\u2570") + dimBorder("\u2500".repeat(inner)) + dimBorder("\u256F");
134
+ const contentLines = rows.map((row) => {
135
+ const visLen = stripAnsi(row);
136
+ const pad = Math.max(0, inner - 1 - visLen);
137
+ return dimBorder("\u2502") + " " + row + " ".repeat(pad) + dimBorder("\u2502");
138
+ });
139
+ return [topLine, ...contentLines, bottomLine].join("\n");
140
+ }
141
+ function formatOptionTerm(opt) {
142
+ const parts = [];
143
+ if (opt.short) parts.push(opt.short);
144
+ if (opt.long) parts.push(opt.long);
145
+ let term = parts.join(", ");
146
+ if (opt.flags) {
147
+ const match = opt.flags.match(/<[^>]+>|\[[^\]]+\]/);
148
+ if (match) {
149
+ term += " " + match[0];
150
+ }
151
+ }
152
+ return term;
153
+ }
154
+ function getLongFlag(opt) {
155
+ if (opt.long) return opt.long;
156
+ return opt.short || "";
157
+ }
158
+ function formatDefault(opt) {
159
+ if (opt.defaultValue !== void 0 && opt.defaultValue !== false) {
160
+ return dim(` [default: ${opt.defaultValue}]`);
161
+ }
162
+ return "";
163
+ }
164
+ function richFormatHelp(cmd, helper) {
165
+ const width = process.stdout.columns || 80;
166
+ const lines = [];
167
+ const isRoot = !cmd.parent;
168
+ const usage = helper.commandUsage(cmd);
169
+ lines.push("");
170
+ if (isRoot) {
171
+ lines.push(` ${yellow("Usage:")} ${bold(cmd.name())} ${yellow("<command>")} ${bold("[options]")}`);
172
+ } else {
173
+ const usageParts = usage.split(" ");
174
+ const cmdPath = [];
175
+ const argParts = [];
176
+ let pastCmd = false;
177
+ for (const part of usageParts) {
178
+ if (!pastCmd && !part.startsWith("[") && !part.startsWith("<")) {
179
+ cmdPath.push(part);
180
+ } else {
181
+ pastCmd = true;
182
+ argParts.push(part);
183
+ }
184
+ }
185
+ lines.push(` ${yellow("Usage:")} ${bold(cmdPath.join(" "))} ${yellow(argParts.join(" "))}`);
186
+ }
187
+ lines.push("");
188
+ const desc = helper.commandDescription(cmd);
189
+ if (desc) {
190
+ const descLines = desc.split("\n");
191
+ for (let i = 0; i < descLines.length; i++) {
192
+ const dLine = descLines[i];
193
+ if (i === 0 || dLine.trim() === "") {
194
+ lines.push(` ${dLine}`);
195
+ } else {
196
+ lines.push(` ${dim(dLine)}`);
197
+ }
198
+ }
199
+ lines.push("");
200
+ }
201
+ if (!isRoot) {
202
+ const visibleArgs = helper.visibleArguments(cmd);
203
+ if (visibleArgs.length > 0) {
204
+ const maxLen = Math.max(...visibleArgs.map((a) => a.name().length));
205
+ const argRows = visibleArgs.map((a) => {
206
+ const name = cyanBold(a.name().padEnd(maxLen));
207
+ const description = helper.argumentDescription(a);
208
+ return ` ${name} ${description}`;
209
+ });
210
+ const panel = renderPanel("Arguments", argRows, width);
211
+ if (panel) lines.push(panel);
212
+ }
213
+ }
214
+ const visibleOpts = helper.visibleOptions(cmd);
215
+ const cmdName = cmd.name();
216
+ const panelMap = !isRoot && OPTION_PANELS[cmdName] ? OPTION_PANELS[cmdName] : {};
217
+ const grouped = { Options: [] };
218
+ for (const panelName of PANEL_ORDER) {
219
+ grouped[panelName] = [];
220
+ }
221
+ for (const opt of visibleOpts) {
222
+ const flag = getLongFlag(opt);
223
+ const panel = panelMap[flag];
224
+ if (panel && PANEL_ORDER.includes(panel)) {
225
+ grouped[panel].push(opt);
226
+ } else {
227
+ grouped["Options"].push(opt);
228
+ }
229
+ }
230
+ const visibleCmds = helper.visibleCommands(cmd);
231
+ if (isRoot) {
232
+ if (grouped["Options"].length > 0) {
233
+ const optRows = formatOptionRows(grouped["Options"]);
234
+ const panel = renderPanel("Options", optRows, width);
235
+ if (panel) lines.push(panel);
236
+ }
237
+ if (visibleCmds.length > 0) {
238
+ const cmdMap = new Map(visibleCmds.map((c) => [c.name(), c]));
239
+ for (const group of COMMAND_GROUPS) {
240
+ const groupCmds = group.commands.map((name) => cmdMap.get(name)).filter((c) => c !== void 0);
241
+ if (groupCmds.length === 0) continue;
242
+ const maxLen = Math.max(...groupCmds.map((c) => c.name().length));
243
+ const cmdRows = groupCmds.map((c) => {
244
+ const name = cyanBold(c.name().padEnd(maxLen));
245
+ const description = helper.subcommandDescription(c);
246
+ return ` ${name} ${description}`;
247
+ });
248
+ const panel = renderPanel(group.panel, cmdRows, width);
249
+ if (panel) lines.push(panel);
250
+ }
251
+ }
252
+ } else {
253
+ const panelSequence = ["Options", ...PANEL_ORDER];
254
+ for (const panelName of panelSequence) {
255
+ const opts = grouped[panelName];
256
+ if (opts && opts.length > 0) {
257
+ const optRows = formatOptionRows(opts);
258
+ const panel = renderPanel(panelName, optRows, width);
259
+ if (panel) lines.push(panel);
260
+ }
261
+ }
262
+ if (visibleCmds.length > 0) {
263
+ const maxLen = Math.max(...visibleCmds.map((c) => c.name().length));
264
+ const cmdRows = visibleCmds.map((c) => {
265
+ const name = cyanBold(c.name().padEnd(maxLen));
266
+ const description = helper.subcommandDescription(c);
267
+ return ` ${name} ${description}`;
268
+ });
269
+ const panel = renderPanel("Commands", cmdRows, width);
270
+ if (panel) lines.push(panel);
271
+ }
272
+ }
273
+ lines.push("");
274
+ return lines.join("\n");
275
+ }
276
+ function formatOptionRows(opts) {
277
+ const terms = opts.map((o) => formatOptionTerm(o));
278
+ const maxTermLen = Math.max(...terms.map((t) => t.length));
279
+ return opts.map((opt, i) => {
280
+ const term = cyanBold(terms[i].padEnd(maxTermLen));
281
+ const desc = opt.description || "";
282
+ const def = formatDefault(opt);
283
+ return ` ${term} ${desc}${def}`;
284
+ });
285
+ }
286
+
287
+ // src/index.ts
288
+ var _require = createRequire(import.meta.url);
289
+ var VERSION = _require("../package.json").version;
290
+ var program = new Command();
291
+ function getBackendAndConfig(apiKey, baseUrl) {
292
+ const config = loadConfig();
293
+ if (apiKey) config.platform.apiKey = apiKey;
294
+ if (baseUrl) config.platform.baseUrl = baseUrl;
295
+ if (!config.platform.apiKey) {
296
+ printError(
297
+ "No API key configured.",
298
+ "Run 'mem0 init' or set MEM0_API_KEY environment variable."
299
+ );
300
+ process.exit(1);
301
+ }
302
+ return { backend: getBackend(config), config };
303
+ }
304
+ function getBackendOnly(apiKey, baseUrl) {
305
+ return getBackendAndConfig(apiKey, baseUrl).backend;
306
+ }
307
+ function resolveIds(config, opts) {
308
+ const hasExplicit = !!(opts.userId || opts.agentId || opts.appId || opts.runId);
309
+ if (hasExplicit) {
310
+ return {
311
+ userId: opts.userId || void 0,
312
+ agentId: opts.agentId || void 0,
313
+ appId: opts.appId || void 0,
314
+ runId: opts.runId || void 0
315
+ };
316
+ }
317
+ return {
318
+ userId: config.defaults.userId || void 0,
319
+ agentId: config.defaults.agentId || void 0,
320
+ appId: config.defaults.appId || void 0,
321
+ runId: config.defaults.runId || void 0
322
+ };
323
+ }
324
+ function resolveGraph(config, opts) {
325
+ if (opts.noGraph) return false;
326
+ if (opts.graph) return true;
327
+ return config.defaults.enableGraph;
328
+ }
329
+ program.name("mem0").description(`\u25C6 Mem0 CLI v${VERSION} \xB7 Node.js SDK
330
+
331
+ The Memory Layer for AI Agents`).option("--version", "Show version and exit.").on("option:version", () => {
332
+ console.log(` ${colors.brand("\u25C6 Mem0")} CLI v${VERSION}`);
333
+ process.exit(0);
334
+ }).usage("<command> [options]").helpOption("--help", "Show this message and exit.").addHelpCommand(false).configureHelp({ formatHelp: richFormatHelp });
335
+ program.command("init").description("Interactive setup wizard for mem0 CLI.").option("--api-key <key>", "API key (skip prompt).").option("-u, --user-id <id>", "Default user ID (skip prompt).").addHelpText("after", "\nExamples:\n $ mem0 init\n $ mem0 init --api-key m0-xxx --user-id alice").action(async (opts) => {
336
+ const { runInit } = await import("./init-N25QFHYP.js");
337
+ await runInit({ apiKey: opts.apiKey, userId: opts.userId });
338
+ });
339
+ program.command("add [text]").description("Add a memory from text, messages, file, or stdin.").option("-u, --user-id <id>", "Scope to user.").option("--agent-id <id>", "Scope to agent.").option("--app-id <id>", "Scope to app.").option("--run-id <id>", "Scope to run.").option("--messages <json>", "Conversation messages as JSON.").option("-f, --file <path>", "Read messages from JSON file.").option("-m, --metadata <json>", "Custom metadata as JSON.").option("--immutable", "Prevent future updates.", false).option("--no-infer", "Skip inference, store raw.").option("--expires <date>", "Expiration date (YYYY-MM-DD).").option("--categories <value>", "Categories (JSON array or comma-separated).").option("--graph", "Enable graph memory extraction.", false).option("--no-graph", "Disable graph memory extraction.").option("-o, --output <format>", "Output format: text, json, quiet.", "text").option("--api-key <key>", "Override API key.").option("--base-url <url>", "Override API base URL.").addHelpText("after", '\nExamples:\n $ mem0 add "I prefer dark mode" --user-id alice\n $ echo "text" | mem0 add -u alice\n $ mem0 add --file msgs.json -u alice -o json').action(async (text, opts) => {
340
+ const { cmdAdd } = await import("./memory-JYJGE4VO.js");
341
+ const { backend, config } = getBackendAndConfig(opts.apiKey, opts.baseUrl);
342
+ const ids = resolveIds(config, opts);
343
+ const enableGraph = resolveGraph(config, opts);
344
+ await cmdAdd(backend, text, { ...ids, ...opts, enableGraph });
345
+ });
346
+ program.command("search [query]").description("Search memories by semantic query.").option("-u, --user-id <id>", "Filter by user.").option("--agent-id <id>", "Filter by agent.").option("--app-id <id>", "Filter by app.").option("--run-id <id>", "Filter by run.").option("-k, --top-k <n>", "Number of results.", (v) => parseInt(v), 10).option("--threshold <n>", "Minimum similarity score.", (v) => parseFloat(v), 0.3).option("--rerank", "Enable reranking (Platform only).", false).option("--keyword", "Use keyword search.", false).option("--filter <json>", "Advanced filter expression (JSON).").option("--fields <list>", "Specific fields to return (comma-separated).").option("--graph", "Enable graph in search.", false).option("--no-graph", "Disable graph in search.").option("-o, --output <format>", "Output: text, json, table.", "text").option("--api-key <key>", "Override API key.").option("--base-url <url>", "Override API base URL.").addHelpText("after", '\nExamples:\n $ mem0 search "preferences" --user-id alice\n $ mem0 search "tools" -u alice -o json -k 5\n $ echo "preferences" | mem0 search -u alice').action(async (query, opts) => {
347
+ let resolvedQuery = query;
348
+ if (!resolvedQuery && !process.stdin.isTTY) {
349
+ resolvedQuery = fs.readFileSync(0, "utf-8").trim();
350
+ }
351
+ if (!resolvedQuery) {
352
+ printError("No query provided. Pass a query argument or pipe via stdin.");
353
+ process.exit(1);
354
+ }
355
+ const { cmdSearch } = await import("./memory-JYJGE4VO.js");
356
+ const { backend, config } = getBackendAndConfig(opts.apiKey, opts.baseUrl);
357
+ const ids = resolveIds(config, opts);
358
+ const enableGraph = resolveGraph(config, opts);
359
+ await cmdSearch(backend, resolvedQuery, {
360
+ ...ids,
361
+ topK: opts.topK,
362
+ threshold: opts.threshold,
363
+ rerank: opts.rerank,
364
+ keyword: opts.keyword,
365
+ filterJson: opts.filter,
366
+ fields: opts.fields,
367
+ enableGraph,
368
+ output: opts.output
369
+ });
370
+ });
371
+ program.command("get <memoryId>").description("Get a specific memory by ID.").option("-o, --output <format>", "Output: text, json.", "text").option("--api-key <key>", "Override API key.").option("--base-url <url>", "Override API base URL.").addHelpText("after", "\nExamples:\n $ mem0 get abc-123-def-456\n $ mem0 get abc-123-def-456 -o json").action(async (memoryId, opts) => {
372
+ const { cmdGet } = await import("./memory-JYJGE4VO.js");
373
+ const backend = getBackendOnly(opts.apiKey, opts.baseUrl);
374
+ await cmdGet(backend, memoryId, { output: opts.output });
375
+ });
376
+ program.command("list").description("List memories with optional filters.").option("-u, --user-id <id>", "Filter by user.").option("--agent-id <id>", "Filter by agent.").option("--app-id <id>", "Filter by app.").option("--run-id <id>", "Filter by run.").option("--page <n>", "Page number.", (v) => parseInt(v), 1).option("--page-size <n>", "Results per page.", (v) => parseInt(v), 100).option("--category <name>", "Filter by category.").option("--after <date>", "Created after (YYYY-MM-DD).").option("--before <date>", "Created before (YYYY-MM-DD).").option("--graph", "Enable graph in listing.", false).option("--no-graph", "Disable graph in listing.").option("-o, --output <format>", "Output: text, json, table.", "table").option("--api-key <key>", "Override API key.").option("--base-url <url>", "Override API base URL.").addHelpText("after", "\nExamples:\n $ mem0 list -u alice\n $ mem0 list --category prefs --after 2024-01-01 -o json").action(async (opts) => {
377
+ const { cmdList } = await import("./memory-JYJGE4VO.js");
378
+ const { backend, config } = getBackendAndConfig(opts.apiKey, opts.baseUrl);
379
+ const ids = resolveIds(config, opts);
380
+ const enableGraph = resolveGraph(config, opts);
381
+ await cmdList(backend, {
382
+ ...ids,
383
+ page: opts.page,
384
+ pageSize: opts.pageSize,
385
+ category: opts.category,
386
+ after: opts.after,
387
+ before: opts.before,
388
+ enableGraph,
389
+ output: opts.output
390
+ });
391
+ });
392
+ program.command("update <memoryId> [text]").description("Update a memory's text or metadata.").option("-m, --metadata <json>", "Update metadata (JSON).").option("-o, --output <format>", "Output: text, json, quiet.", "text").option("--api-key <key>", "Override API key.").option("--base-url <url>", "Override API base URL.").addHelpText("after", `
393
+ Examples:
394
+ $ mem0 update abc-123 "new text"
395
+ $ mem0 update abc-123 --metadata '{"key":"val"}'
396
+ $ echo "new text" | mem0 update abc-123`).action(async (memoryId, text, opts) => {
397
+ let resolvedText = text;
398
+ if (!resolvedText && !opts.metadata && !process.stdin.isTTY) {
399
+ resolvedText = fs.readFileSync(0, "utf-8").trim();
400
+ }
401
+ const { cmdUpdate } = await import("./memory-JYJGE4VO.js");
402
+ const backend = getBackendOnly(opts.apiKey, opts.baseUrl);
403
+ await cmdUpdate(backend, memoryId, resolvedText, { metadata: opts.metadata, output: opts.output });
404
+ });
405
+ program.command("delete [memoryId]").description("Delete a memory, all memories matching a scope, or an entity.").option("--all", "Delete all memories matching scope filters.", false).option("--entity", "Delete the entity itself and all its memories (cascade).", false).option("--project", "With --all: delete ALL memories project-wide.", false).option("--dry-run", "Show what would be deleted without deleting.", false).option("--force", "Skip confirmation.", false).option("-u, --user-id <id>", "Scope to user.").option("--agent-id <id>", "Scope to agent.").option("--app-id <id>", "Scope to app.").option("--run-id <id>", "Scope to run.").option("-o, --output <format>", "Output: text, json, quiet.", "text").option("--api-key <key>", "Override API key.").option("--base-url <url>", "Override API base URL.").addHelpText("after", [
406
+ "\nExamples:",
407
+ " $ mem0 delete abc-123-def-456 # single memory",
408
+ " $ mem0 delete --all -u alice --force # all memories for user",
409
+ " $ mem0 delete --all --project --force # project-wide wipe",
410
+ " $ mem0 delete --entity -u alice --force # entity + all its memories"
411
+ ].join("\n")).action(async (memoryId, opts) => {
412
+ if (memoryId && opts.all) {
413
+ printError("Cannot combine <memoryId> with --all. Use one or the other.");
414
+ process.exit(1);
415
+ }
416
+ if (memoryId && opts.entity) {
417
+ printError("Cannot combine <memoryId> with --entity. Use one or the other.");
418
+ process.exit(1);
419
+ }
420
+ if (opts.all && opts.entity) {
421
+ printError("Cannot combine --all with --entity. Use one or the other.");
422
+ process.exit(1);
423
+ }
424
+ if (!memoryId && !opts.all && !opts.entity) {
425
+ printError(
426
+ "Specify a memory ID, --all, or --entity.\n mem0 delete <id> Delete a single memory\n mem0 delete --all [scope] Delete all memories matching scope\n mem0 delete --entity [scope] Delete an entity and all its memories"
427
+ );
428
+ process.exit(1);
429
+ }
430
+ if (memoryId) {
431
+ const { cmdDelete } = await import("./memory-JYJGE4VO.js");
432
+ const backend = getBackendOnly(opts.apiKey, opts.baseUrl);
433
+ await cmdDelete(backend, memoryId, { output: opts.output, dryRun: opts.dryRun, force: opts.force });
434
+ return;
435
+ }
436
+ if (opts.all) {
437
+ const { cmdDeleteAll } = await import("./memory-JYJGE4VO.js");
438
+ const { backend, config } = getBackendAndConfig(opts.apiKey, opts.baseUrl);
439
+ const ids = opts.project ? { userId: void 0, agentId: void 0, appId: void 0, runId: void 0 } : resolveIds(config, opts);
440
+ await cmdDeleteAll(backend, { force: opts.force, dryRun: opts.dryRun, all: opts.project, ...ids, output: opts.output });
441
+ return;
442
+ }
443
+ if (opts.entity) {
444
+ const { cmdEntitiesDelete } = await import("./entities-XPRXH4X4.js");
445
+ const backend = getBackendOnly(opts.apiKey, opts.baseUrl);
446
+ await cmdEntitiesDelete(backend, opts);
447
+ return;
448
+ }
449
+ });
450
+ var configCmd = program.command("config").description("Manage mem0 configuration.").addHelpCommand(false);
451
+ configCmd.command("show").description("Display current configuration (secrets redacted).").option("-o, --output <format>", "Output: text, json.", "text").addHelpText("after", "\nExamples:\n $ mem0 config show\n $ mem0 config show -o json").action(async (opts) => {
452
+ const { cmdConfigShow } = await import("./config-WKOCXNAS.js");
453
+ cmdConfigShow({ output: opts.output });
454
+ });
455
+ configCmd.command("get <key>").description("Get a configuration value.").addHelpText("after", "\nExamples:\n $ mem0 config get platform.api_key\n $ mem0 config get defaults.user_id").action(async (key) => {
456
+ const { cmdConfigGet } = await import("./config-WKOCXNAS.js");
457
+ cmdConfigGet(key);
458
+ });
459
+ configCmd.command("set <key> <value>").description("Set a configuration value.").addHelpText("after", "\nExamples:\n $ mem0 config set defaults.user_id alice\n $ mem0 config set platform.base_url https://api.mem0.ai").action(async (key, value) => {
460
+ const { cmdConfigSet } = await import("./config-WKOCXNAS.js");
461
+ cmdConfigSet(key, value);
462
+ });
463
+ var entityCmd = program.command("entity").description("Manage entities.").addHelpCommand(false).configureHelp({ formatHelp: richFormatHelp });
464
+ entityCmd.command("list <entityType>").description("List all entities of a given type.").option("-o, --output <format>", "Output: table, json.", "table").option("--api-key <key>", "Override API key.").option("--base-url <url>", "Override API base URL.").addHelpText("after", "\nExamples:\n $ mem0 entity list users\n $ mem0 entity list agents -o json").action(async (entityType, opts) => {
465
+ const { cmdEntitiesList } = await import("./entities-XPRXH4X4.js");
466
+ const backend = getBackendOnly(opts.apiKey, opts.baseUrl);
467
+ await cmdEntitiesList(backend, entityType, { output: opts.output });
468
+ });
469
+ entityCmd.command("delete").description("Delete an entity and ALL its memories (cascade).").option("--dry-run", "Show what would be deleted without deleting.", false).option("-u, --user-id <id>", "Scope to user.").option("--agent-id <id>", "Scope to agent.").option("--app-id <id>", "Scope to app.").option("--run-id <id>", "Scope to run.").option("--force", "Skip confirmation.", false).option("-o, --output <format>", "Output: text, json, quiet.", "text").option("--api-key <key>", "Override API key.").option("--base-url <url>", "Override API base URL.").addHelpText("after", "\nExamples:\n $ mem0 entity delete --user-id alice --force\n $ mem0 entity delete --user-id alice --dry-run").action(async (opts) => {
470
+ const { cmdEntitiesDelete } = await import("./entities-XPRXH4X4.js");
471
+ const backend = getBackendOnly(opts.apiKey, opts.baseUrl);
472
+ await cmdEntitiesDelete(backend, opts);
473
+ });
474
+ program.command("status").description("Check connectivity and authentication.").option("-o, --output <format>", "Output: text, json.", "text").option("--api-key <key>", "Override API key.").option("--base-url <url>", "Override API base URL.").addHelpText("after", "\nExamples:\n $ mem0 status\n $ mem0 status -o json").action(async (opts) => {
475
+ const { cmdStatus } = await import("./utils-BAMFZ5H5.js");
476
+ const { backend, config } = getBackendAndConfig(opts.apiKey, opts.baseUrl);
477
+ await cmdStatus(backend, {
478
+ userId: config.defaults.userId || void 0,
479
+ agentId: config.defaults.agentId || void 0,
480
+ output: opts.output
481
+ });
482
+ });
483
+ program.command("import <filePath>").description("Import memories from a JSON file.").option("-u, --user-id <id>", "Override user ID.").option("--agent-id <id>", "Override agent ID.").option("-o, --output <format>", "Output: text, json.", "text").option("--api-key <key>", "Override API key.").option("--base-url <url>", "Override API base URL.").addHelpText("after", "\nExamples:\n $ mem0 import data.json --user-id alice\n $ mem0 import data.json -u alice -o json").action(async (filePath, opts) => {
484
+ const { cmdImport } = await import("./utils-BAMFZ5H5.js");
485
+ const { backend, config } = getBackendAndConfig(opts.apiKey, opts.baseUrl);
486
+ const ids = resolveIds(config, opts);
487
+ await cmdImport(backend, filePath, { userId: ids.userId, agentId: ids.agentId, output: opts.output });
488
+ });
489
+ program.command("help").description("Show help. Use --json for machine-readable output (for LLM agents).").option("--json", "Output machine-readable JSON for LLM agents.", false).addHelpText("after", "\nExamples:\n $ mem0 help\n $ mem0 help --json").action((opts) => {
490
+ if (opts.json) {
491
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
492
+ const specPath = path.join(__dirname, "..", "..", "cli-spec.json");
493
+ if (fs.existsSync(specPath)) {
494
+ const spec = JSON.parse(fs.readFileSync(specPath, "utf-8"));
495
+ console.log(JSON.stringify(spec, null, 2));
496
+ } else {
497
+ console.log(JSON.stringify({ name: "mem0", version: VERSION, description: "The Memory Layer for AI Agents" }, null, 2));
498
+ }
499
+ } else {
500
+ const { brand: b } = colors;
501
+ console.log(`${b("\u25C6 Mem0 CLI")} v${VERSION} \xB7 Node.js SDK
502
+ The Memory Layer for AI Agents
503
+ `);
504
+ console.log("Usage: mem0 <command> [OPTIONS]\n");
505
+ console.log("Commands:");
506
+ console.log(" add Add a memory from text, messages, file, or stdin");
507
+ console.log(" search Search memories by semantic query");
508
+ console.log(" get Get a specific memory by ID");
509
+ console.log(" list List memories with optional filters");
510
+ console.log(" update Update a memory's text or metadata");
511
+ console.log(" delete Delete a memory, all memories, or an entity");
512
+ console.log(" import Import memories from a JSON file");
513
+ console.log(" config Manage configuration (show, get, set)");
514
+ console.log(" entity Manage entities (list, delete)");
515
+ console.log(" init Interactive setup wizard");
516
+ console.log(" status Check connectivity and authentication");
517
+ console.log();
518
+ console.log(" mem0 <command> --help Get help for a command");
519
+ console.log(" mem0 help --json Machine-readable help (for LLM agents)");
520
+ console.log();
521
+ }
522
+ });
523
+ program.parse();