mcp-agents-memory 0.9.21 → 0.9.22
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/build/index.js +68 -25
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -33364,6 +33364,61 @@ async function hideDeleted(targets, dryRun) {
|
|
|
33364
33364
|
const r = await db.query(sql, [uuids]);
|
|
33365
33365
|
return Number(r.rows[0]?.n ?? 0);
|
|
33366
33366
|
}
|
|
33367
|
+
async function replaceWithCleaned(id, cleaned, original, venue) {
|
|
33368
|
+
const client2 = await db.getClient();
|
|
33369
|
+
try {
|
|
33370
|
+
await client2.query("BEGIN");
|
|
33371
|
+
await client2.query("SET LOCAL lock_timeout = '2s'");
|
|
33372
|
+
const r = await client2.query(
|
|
33373
|
+
`UPDATE memory
|
|
33374
|
+
SET message = $2, raw_message = $3, venue = coalesce(venue, $4),
|
|
33375
|
+
p_tag_id = NULL, d_tag = '{}', tag_processed = FALSE, embedding = NULL, cold_error = NULL
|
|
33376
|
+
WHERE id = $1 AND raw_message IS NULL AND message = $3`,
|
|
33377
|
+
[id, cleaned, original, venue]
|
|
33378
|
+
);
|
|
33379
|
+
await client2.query("COMMIT");
|
|
33380
|
+
client2.release();
|
|
33381
|
+
return (r.rowCount ?? 0) > 0;
|
|
33382
|
+
} catch (err3) {
|
|
33383
|
+
let broken;
|
|
33384
|
+
await client2.query("ROLLBACK").catch((e) => broken = e);
|
|
33385
|
+
client2.release(broken);
|
|
33386
|
+
if (err3.code !== "55P03") throw err3;
|
|
33387
|
+
return false;
|
|
33388
|
+
}
|
|
33389
|
+
}
|
|
33390
|
+
async function healBaseEnvelopes(userId, budget, dryRun) {
|
|
33391
|
+
const rows = (await db.query(
|
|
33392
|
+
`SELECT id, message, device_name FROM memory
|
|
33393
|
+
WHERE user_id = $1 AND role = 'user' AND raw_message IS NULL AND message ~ '^\\s*<base>'
|
|
33394
|
+
AND agent_platform <> 'buzz' AND is_active AND NOT is_pinned
|
|
33395
|
+
ORDER BY created_at, id`,
|
|
33396
|
+
[userId]
|
|
33397
|
+
)).rows;
|
|
33398
|
+
const byDevice = {};
|
|
33399
|
+
let healed = 0;
|
|
33400
|
+
let ready = 0;
|
|
33401
|
+
let rejected = 0;
|
|
33402
|
+
for (const r of rows) {
|
|
33403
|
+
const cleaned = cleanBuzzEnvelope(r.message);
|
|
33404
|
+
if (cleaned === null) {
|
|
33405
|
+
rejected++;
|
|
33406
|
+
continue;
|
|
33407
|
+
}
|
|
33408
|
+
if (healed >= budget) {
|
|
33409
|
+
ready++;
|
|
33410
|
+
continue;
|
|
33411
|
+
}
|
|
33412
|
+
if (dryRun || await replaceWithCleaned(Number(r.id), cleaned, r.message, buzzTurnVenue(cleaned))) {
|
|
33413
|
+
healed++;
|
|
33414
|
+
const d = r.device_name ?? "unknown";
|
|
33415
|
+
byDevice[d] = (byDevice[d] ?? 0) + 1;
|
|
33416
|
+
} else {
|
|
33417
|
+
ready++;
|
|
33418
|
+
}
|
|
33419
|
+
}
|
|
33420
|
+
return { healed, byDevice, ready, rejected };
|
|
33421
|
+
}
|
|
33367
33422
|
async function recleanEnvelopes(userId, budget, dryRun) {
|
|
33368
33423
|
const rows = (await db.query(
|
|
33369
33424
|
`SELECT id, message, venue FROM memory
|
|
@@ -33401,29 +33456,7 @@ async function recleanEnvelopes(userId, budget, dryRun) {
|
|
|
33401
33456
|
stuck += cands.length - ready.length;
|
|
33402
33457
|
let n = 0;
|
|
33403
33458
|
for (const c of ready.slice(0, Math.max(0, budget))) {
|
|
33404
|
-
if (dryRun)
|
|
33405
|
-
n++;
|
|
33406
|
-
continue;
|
|
33407
|
-
}
|
|
33408
|
-
const client2 = await db.getClient();
|
|
33409
|
-
try {
|
|
33410
|
-
await client2.query("BEGIN");
|
|
33411
|
-
await client2.query("SET LOCAL lock_timeout = '2s'");
|
|
33412
|
-
const r = await client2.query(
|
|
33413
|
-
`UPDATE memory
|
|
33414
|
-
SET message = $2, raw_message = $3, tag_processed = FALSE, embedding = NULL, cold_error = NULL
|
|
33415
|
-
WHERE id = $1 AND raw_message IS NULL AND message = $3`,
|
|
33416
|
-
[c.id, c.cleaned, c.message]
|
|
33417
|
-
);
|
|
33418
|
-
await client2.query("COMMIT");
|
|
33419
|
-
n += r.rowCount ?? 0;
|
|
33420
|
-
} catch (err3) {
|
|
33421
|
-
await client2.query("ROLLBACK").catch(() => {
|
|
33422
|
-
});
|
|
33423
|
-
if (err3.code !== "55P03") throw err3;
|
|
33424
|
-
} finally {
|
|
33425
|
-
client2.release();
|
|
33426
|
-
}
|
|
33459
|
+
if (dryRun || await replaceWithCleaned(c.id, c.cleaned, c.message, c.venue)) n++;
|
|
33427
33460
|
}
|
|
33428
33461
|
return { recleaned: n, ready: ready.length - n, stuck };
|
|
33429
33462
|
}
|
|
@@ -33461,6 +33494,10 @@ async function runBuzzIngest(opts = {}) {
|
|
|
33461
33494
|
inserted: 0,
|
|
33462
33495
|
edited: 0,
|
|
33463
33496
|
hidden: 0,
|
|
33497
|
+
healed: 0,
|
|
33498
|
+
healedByDevice: {},
|
|
33499
|
+
healReady: 0,
|
|
33500
|
+
healRejected: 0,
|
|
33464
33501
|
recleaned: 0,
|
|
33465
33502
|
envelopesReady: 0,
|
|
33466
33503
|
envelopesStuck: 0,
|
|
@@ -33496,7 +33533,12 @@ async function runBuzzIngest(opts = {}) {
|
|
|
33496
33533
|
report.edited = await applyEdits(latestEdits(edits), dryRun);
|
|
33497
33534
|
report.hidden = await hideDeleted([...deleteTargets], dryRun);
|
|
33498
33535
|
if (!opts.noReclean && userId > 0) {
|
|
33499
|
-
const
|
|
33536
|
+
const heal = await healBaseEnvelopes(userId, max - batch.length, dryRun);
|
|
33537
|
+
report.healed = heal.healed;
|
|
33538
|
+
report.healedByDevice = heal.byDevice;
|
|
33539
|
+
report.healReady = heal.ready;
|
|
33540
|
+
report.healRejected = heal.rejected;
|
|
33541
|
+
const env = await recleanEnvelopes(userId, max - batch.length - heal.healed, dryRun);
|
|
33500
33542
|
report.recleaned = env.recleaned;
|
|
33501
33543
|
report.envelopesReady = env.ready;
|
|
33502
33544
|
report.envelopesStuck = env.stuck;
|
|
@@ -33524,6 +33566,7 @@ var init_buzz_ingest = __esm({
|
|
|
33524
33566
|
init_db();
|
|
33525
33567
|
init_hot_path();
|
|
33526
33568
|
init_buzz_envelope();
|
|
33569
|
+
init_venue();
|
|
33527
33570
|
init_users();
|
|
33528
33571
|
KIND_CHAT = 9;
|
|
33529
33572
|
KIND_EDIT = 40003;
|
|
@@ -62251,7 +62294,7 @@ Usage:
|
|
|
62251
62294
|
into memory, one row per message, via the official \`buzz\` CLI. Oldest first, at most
|
|
62252
62295
|
N per run (default 20). With the remaining budget it also strips the quoted history
|
|
62253
62296
|
from captured Buzz turns once every quoted message exists as a row (original kept in
|
|
62254
|
-
raw_message; --no-reclean skips
|
|
62297
|
+
raw_message), and fixes Buzz envelopes an older server stored uncleaned; --no-reclean skips both. Needs BUZZ_RELAY_URL, BUZZ_PRIVATE_KEY and BUZZ_INGEST_OWNER
|
|
62255
62298
|
(the memory owner's pubkeys, comma-separated) in the environment of this command only \u2014
|
|
62256
62299
|
not in the shared .env; optional BUZZ_CLI.
|
|
62257
62300
|
mcp-agents-memory help Show this message.
|