@hasna/mementos 0.4.37 → 0.4.39
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/cli/index.js +100 -7
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -5214,6 +5214,65 @@ mementos report \u2014 last ${days} days
|
|
|
5214
5214
|
process.exit(1);
|
|
5215
5215
|
}
|
|
5216
5216
|
});
|
|
5217
|
+
program2.command("stale").description("Find memories not accessed recently (for cleanup/review)").option("--days <n>", "Stale threshold in days (default: 30)", parseInt).option("--project <path>", "Project filter").option("--agent <name>", "Agent filter").option("--limit <n>", "Max results (default: 20)", parseInt).option("--format <fmt>", "Output format: compact (default), json").action((opts) => {
|
|
5218
|
+
try {
|
|
5219
|
+
const globalOpts = program2.opts();
|
|
5220
|
+
const days = opts.days || 30;
|
|
5221
|
+
const limit = opts.limit || 20;
|
|
5222
|
+
const projectPath = opts.project || globalOpts.project;
|
|
5223
|
+
let projectId;
|
|
5224
|
+
if (projectPath) {
|
|
5225
|
+
const project = getProject(resolve3(projectPath));
|
|
5226
|
+
if (project)
|
|
5227
|
+
projectId = project.id;
|
|
5228
|
+
}
|
|
5229
|
+
const agentName = opts.agent || globalOpts.agent;
|
|
5230
|
+
let agentId;
|
|
5231
|
+
if (agentName) {
|
|
5232
|
+
const agent = getAgent(agentName);
|
|
5233
|
+
if (agent)
|
|
5234
|
+
agentId = agent.id;
|
|
5235
|
+
}
|
|
5236
|
+
const db = getDatabase();
|
|
5237
|
+
const conds = [
|
|
5238
|
+
"status = 'active'",
|
|
5239
|
+
`(accessed_at IS NULL OR accessed_at < datetime('now', '-${days} days'))`,
|
|
5240
|
+
"pinned = 0"
|
|
5241
|
+
];
|
|
5242
|
+
const params = [];
|
|
5243
|
+
if (projectId) {
|
|
5244
|
+
conds.push("project_id = ?");
|
|
5245
|
+
params.push(projectId);
|
|
5246
|
+
}
|
|
5247
|
+
if (agentId) {
|
|
5248
|
+
conds.push("agent_id = ?");
|
|
5249
|
+
params.push(agentId);
|
|
5250
|
+
}
|
|
5251
|
+
const rows = db.query(`SELECT id, key, value, importance, scope, category, accessed_at, access_count FROM memories WHERE ${conds.join(" AND ")} ORDER BY COALESCE(accessed_at, created_at) ASC LIMIT ?`).all(...params, limit);
|
|
5252
|
+
const fmt = getOutputFormat(opts.format);
|
|
5253
|
+
if (fmt === "json") {
|
|
5254
|
+
outputJson({ memories: rows, count: rows.length, days });
|
|
5255
|
+
return;
|
|
5256
|
+
}
|
|
5257
|
+
if (rows.length === 0) {
|
|
5258
|
+
console.log(chalk.green(`No stale memories (not accessed in ${days}+ days).`));
|
|
5259
|
+
return;
|
|
5260
|
+
}
|
|
5261
|
+
console.log(chalk.bold(`
|
|
5262
|
+
Stale memories (not accessed in ${days}+ days):
|
|
5263
|
+
`));
|
|
5264
|
+
for (const m of rows) {
|
|
5265
|
+
const lastAccess = m.accessed_at ? m.accessed_at.slice(0, 10) : chalk.dim("never");
|
|
5266
|
+
console.log(` ${chalk.dim(`[${m.importance}]`)} ${chalk.bold(m.key)} ${chalk.dim(`(${m.scope}/${m.category})`)}`);
|
|
5267
|
+
console.log(` Last accessed: ${lastAccess} \xB7 ${m.access_count} reads \xB7 ${m.value.slice(0, 80)}${m.value.length > 80 ? "..." : ""}`);
|
|
5268
|
+
}
|
|
5269
|
+
console.log(`
|
|
5270
|
+
${chalk.dim(`${rows.length} result(s). Run 'mementos archive <key>' or 'mementos forget <key>' to clean up.`)}`);
|
|
5271
|
+
} catch (e) {
|
|
5272
|
+
console.error(chalk.red(`stale failed: ${e instanceof Error ? e.message : String(e)}`));
|
|
5273
|
+
process.exit(1);
|
|
5274
|
+
}
|
|
5275
|
+
});
|
|
5217
5276
|
program2.command("export").description("Export memories as JSON").option("-s, --scope <scope>", "Scope filter").option("-c, --category <cat>", "Category filter").option("--agent <name>", "Agent filter").option("--project <path>", "Project filter").action((opts) => {
|
|
5218
5277
|
try {
|
|
5219
5278
|
const globalOpts = program2.opts();
|
|
@@ -5404,7 +5463,7 @@ program2.command("projects").description("Manage projects").option("--add", "Add
|
|
|
5404
5463
|
handleError(e);
|
|
5405
5464
|
}
|
|
5406
5465
|
});
|
|
5407
|
-
program2.command("inject").description("Output injection context for agent system prompts").option("--agent <name>", "Agent ID for scope filtering").option("--project <path>", "Project path for scope filtering").option("--session <id>", "Session ID for scope filtering").option("--max-tokens <n>", "Max approximate token budget", parseInt).option("--categories <cats>", "Comma-separated categories to include").action((opts) => {
|
|
5466
|
+
program2.command("inject").description("Output injection context for agent system prompts").option("--agent <name>", "Agent ID for scope filtering").option("--project <path>", "Project path for scope filtering").option("--session <id>", "Session ID for scope filtering").option("--max-tokens <n>", "Max approximate token budget", parseInt).option("--categories <cats>", "Comma-separated categories to include").option("--format <fmt>", "Output format: xml (default), compact, markdown, json").action((opts) => {
|
|
5408
5467
|
try {
|
|
5409
5468
|
const globalOpts = program2.opts();
|
|
5410
5469
|
const maxTokens = opts.maxTokens || 500;
|
|
@@ -5468,8 +5527,16 @@ program2.command("inject").description("Output injection context for agent syste
|
|
|
5468
5527
|
const charBudget = maxTokens * 4;
|
|
5469
5528
|
const lines = [];
|
|
5470
5529
|
let totalChars = 0;
|
|
5530
|
+
const fmt = opts.format || "xml";
|
|
5471
5531
|
for (const m of unique) {
|
|
5472
|
-
|
|
5532
|
+
let line;
|
|
5533
|
+
if (fmt === "compact") {
|
|
5534
|
+
line = `${m.key}: ${m.value}`;
|
|
5535
|
+
} else if (fmt === "json") {
|
|
5536
|
+
line = JSON.stringify({ key: m.key, value: m.value, scope: m.scope, category: m.category, importance: m.importance });
|
|
5537
|
+
} else {
|
|
5538
|
+
line = `- [${m.scope}/${m.category}] ${m.key}: ${m.value}`;
|
|
5539
|
+
}
|
|
5473
5540
|
if (totalChars + line.length > charBudget)
|
|
5474
5541
|
break;
|
|
5475
5542
|
lines.push(line);
|
|
@@ -5484,10 +5551,23 @@ program2.command("inject").description("Output injection context for agent syste
|
|
|
5484
5551
|
}
|
|
5485
5552
|
return;
|
|
5486
5553
|
}
|
|
5487
|
-
|
|
5554
|
+
let context;
|
|
5555
|
+
if (fmt === "compact") {
|
|
5556
|
+
context = lines.join(`
|
|
5557
|
+
`);
|
|
5558
|
+
} else if (fmt === "json") {
|
|
5559
|
+
context = `[${lines.join(",")}]`;
|
|
5560
|
+
} else if (fmt === "markdown") {
|
|
5561
|
+
context = `## Agent Memories
|
|
5562
|
+
|
|
5563
|
+
${lines.join(`
|
|
5564
|
+
`)}`;
|
|
5565
|
+
} else {
|
|
5566
|
+
context = `<agent-memories>
|
|
5488
5567
|
${lines.join(`
|
|
5489
5568
|
`)}
|
|
5490
5569
|
</agent-memories>`;
|
|
5570
|
+
}
|
|
5491
5571
|
if (globalOpts.json) {
|
|
5492
5572
|
outputJson({ context, count: lines.length });
|
|
5493
5573
|
} else {
|
|
@@ -5566,7 +5646,7 @@ program2.command("bulk <action> <ids...>").description("Batch operations: forget
|
|
|
5566
5646
|
handleError(e);
|
|
5567
5647
|
}
|
|
5568
5648
|
});
|
|
5569
|
-
program2.command("doctor").description("Diagnose common issues with the mementos installation").action(() => {
|
|
5649
|
+
program2.command("doctor").description("Diagnose common issues with the mementos installation").action(async () => {
|
|
5570
5650
|
const globalOpts = program2.opts();
|
|
5571
5651
|
const checks = [];
|
|
5572
5652
|
const version = getPackageVersion();
|
|
@@ -5693,9 +5773,22 @@ program2.command("doctor").description("Diagnose common issues with the mementos
|
|
|
5693
5773
|
}
|
|
5694
5774
|
try {
|
|
5695
5775
|
const mementosUrl = process.env["MEMENTOS_URL"] || `http://127.0.0.1:19428`;
|
|
5696
|
-
|
|
5776
|
+
let serverStatus = "warn";
|
|
5777
|
+
let serverDetail = `${mementosUrl} \u2014 not reachable (run 'mementos-serve' to start)`;
|
|
5778
|
+
try {
|
|
5779
|
+
const controller = new AbortController;
|
|
5780
|
+
const timeout = setTimeout(() => controller.abort(), 1000);
|
|
5781
|
+
const res = await fetch(`${mementosUrl}/api/health`, { signal: controller.signal });
|
|
5782
|
+
clearTimeout(timeout);
|
|
5783
|
+
if (res.ok) {
|
|
5784
|
+
const data = await res.json();
|
|
5785
|
+
serverStatus = "ok";
|
|
5786
|
+
serverDetail = `${mementosUrl} \u2014 running v${data.version || "?"} (${data.status || "ok"})`;
|
|
5787
|
+
}
|
|
5788
|
+
} catch {}
|
|
5789
|
+
checks.push({ name: "REST server", status: serverStatus, detail: serverDetail });
|
|
5697
5790
|
} catch {
|
|
5698
|
-
checks.push({ name: "REST server
|
|
5791
|
+
checks.push({ name: "REST server", status: "warn", detail: "Could not check REST server" });
|
|
5699
5792
|
}
|
|
5700
5793
|
outputDoctorResults(globalOpts, checks);
|
|
5701
5794
|
});
|
|
@@ -6551,7 +6644,7 @@ function diffLines(oldText, newText) {
|
|
|
6551
6644
|
}
|
|
6552
6645
|
}
|
|
6553
6646
|
program2.command("completions <shell>").description("Output shell completion script (bash, zsh, fish)").action((shell) => {
|
|
6554
|
-
const commands = "save recall list update forget search stats export import clean inject context pin unpin archive versions doctor tail diff init agents projects bulk completions config backup restore report profile mcp";
|
|
6647
|
+
const commands = "save recall list update forget search stats export import clean inject context pin unpin archive versions stale doctor tail diff init agents projects bulk completions config backup restore report profile mcp";
|
|
6555
6648
|
const commandList = commands.split(" ");
|
|
6556
6649
|
switch (shell.toLowerCase()) {
|
|
6557
6650
|
case "bash": {
|