@hasna/mementos 0.4.25 → 0.4.27
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 +4 -2
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +34 -0
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -5114,6 +5114,8 @@ program2.command("report").description("Rich summary of memory activity and top
|
|
|
5114
5114
|
try {
|
|
5115
5115
|
const globalOpts = program2.opts();
|
|
5116
5116
|
const days = parseInt(opts.days, 10) || 7;
|
|
5117
|
+
const isJson = opts.json || globalOpts.json;
|
|
5118
|
+
const isMarkdown = opts.markdown;
|
|
5117
5119
|
const projectPath = opts.project || globalOpts.project;
|
|
5118
5120
|
let projectId;
|
|
5119
5121
|
if (projectPath) {
|
|
@@ -5139,11 +5141,11 @@ program2.command("report").description("Rich summary of memory activity and top
|
|
|
5139
5141
|
const byCat = Object.fromEntries(byCatRows.map((r) => [r.category, r.c]));
|
|
5140
5142
|
const topMems = db.query(`SELECT key, value, importance, scope, category FROM memories WHERE status = 'active' ${conditions} ORDER BY importance DESC, access_count DESC LIMIT 5`).all(...params);
|
|
5141
5143
|
const topAgents = db.query(`SELECT agent_id, COUNT(*) as c FROM memories WHERE status = 'active' AND agent_id IS NOT NULL ${conditions} GROUP BY agent_id ORDER BY c DESC LIMIT 5`).all(...params);
|
|
5142
|
-
if (
|
|
5144
|
+
if (isJson) {
|
|
5143
5145
|
console.log(JSON.stringify({ total, pinned, recent: { days, total: recentTotal, avg_per_day: parseFloat(avgPerDay) }, by_scope: byScope, by_category: byCat, top_memories: topMems, top_agents: topAgents }, null, 2));
|
|
5144
5146
|
return;
|
|
5145
5147
|
}
|
|
5146
|
-
if (
|
|
5148
|
+
if (isMarkdown) {
|
|
5147
5149
|
const lines = [
|
|
5148
5150
|
`## Mementos Report (last ${days} days)`,
|
|
5149
5151
|
"",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":";AACA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":";AACA;;;GAGG;AA2qCH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAsH9C"}
|
package/dist/server/index.js
CHANGED
|
@@ -2293,6 +2293,40 @@ addRoute("GET", "/api/activity", (_req, url) => {
|
|
|
2293
2293
|
`).all(...params);
|
|
2294
2294
|
return json({ activity: rows, days, total: rows.reduce((s, r) => s + r.memories_created, 0) });
|
|
2295
2295
|
});
|
|
2296
|
+
addRoute("GET", "/api/report", (_req, url) => {
|
|
2297
|
+
const q = getSearchParams(url);
|
|
2298
|
+
const days = Math.min(parseInt(q["days"] || "7", 10), 365);
|
|
2299
|
+
const projectId = q["project_id"];
|
|
2300
|
+
const agentId = q["agent_id"];
|
|
2301
|
+
const db = getDatabase();
|
|
2302
|
+
const cond = [
|
|
2303
|
+
projectId ? "AND project_id = ?" : "",
|
|
2304
|
+
agentId ? "AND agent_id = ?" : ""
|
|
2305
|
+
].filter(Boolean).join(" ");
|
|
2306
|
+
const params = [...projectId ? [projectId] : [], ...agentId ? [agentId] : []];
|
|
2307
|
+
const total = db.query(`SELECT COUNT(*) as c FROM memories WHERE status = 'active' ${cond}`).get(...params).c;
|
|
2308
|
+
const pinned = db.query(`SELECT COUNT(*) as c FROM memories WHERE status = 'active' AND pinned = 1 ${cond}`).get(...params).c;
|
|
2309
|
+
const actRows = db.query(`
|
|
2310
|
+
SELECT date(created_at) AS date, COUNT(*) AS memories_created
|
|
2311
|
+
FROM memories WHERE status = 'active' AND date(created_at) >= date('now', '-${days} days') ${cond}
|
|
2312
|
+
GROUP BY date(created_at) ORDER BY date(created_at) ASC
|
|
2313
|
+
`).all(...params);
|
|
2314
|
+
const recentTotal = actRows.reduce((s, r) => s + r.memories_created, 0);
|
|
2315
|
+
const byScopeRows = db.query(`SELECT scope, COUNT(*) as c FROM memories WHERE status = 'active' ${cond} GROUP BY scope`).all(...params);
|
|
2316
|
+
const byCatRows = db.query(`SELECT category, COUNT(*) as c FROM memories WHERE status = 'active' ${cond} GROUP BY category`).all(...params);
|
|
2317
|
+
const topMems = db.query(`SELECT id, key, value, importance, scope, category FROM memories WHERE status = 'active' ${cond} ORDER BY importance DESC, access_count DESC LIMIT 5`).all(...params);
|
|
2318
|
+
const topAgents = db.query(`SELECT agent_id, COUNT(*) as c FROM memories WHERE status = 'active' AND agent_id IS NOT NULL ${cond} GROUP BY agent_id ORDER BY c DESC LIMIT 5`).all(...params);
|
|
2319
|
+
return json({
|
|
2320
|
+
total,
|
|
2321
|
+
pinned,
|
|
2322
|
+
days,
|
|
2323
|
+
recent: { total: recentTotal, activity: actRows },
|
|
2324
|
+
by_scope: Object.fromEntries(byScopeRows.map((r) => [r.scope, r.c])),
|
|
2325
|
+
by_category: Object.fromEntries(byCatRows.map((r) => [r.category, r.c])),
|
|
2326
|
+
top_memories: topMems,
|
|
2327
|
+
top_agents: topAgents
|
|
2328
|
+
});
|
|
2329
|
+
});
|
|
2296
2330
|
addRoute("POST", "/api/memories/search", async (req) => {
|
|
2297
2331
|
const body = await readJson(req);
|
|
2298
2332
|
if (!body || typeof body["query"] !== "string") {
|