nox-mem 3.11.0 → 3.11.2
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 +3 -0
- package/dist/kg-llm.js +1 -1
- package/dist/session-distill.js +38 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -251,6 +251,9 @@ nox-mem vectorize — embed any unembedded chunks
|
|
|
251
251
|
nox-mem stats — chunk/entity/vector counts
|
|
252
252
|
nox-mem kg-build — extract knowledge graph entities
|
|
253
253
|
nox-mem reflect "question" — synthesis over memory + KG, with cited sources
|
|
254
|
+
nox-mem session-distill — distill memories from agent session JSONL files (Gemini; oldest first; --dry-run,
|
|
255
|
+
--agents, --lookback-days, --max-sessions); stored as `distilled`, which never decays.
|
|
256
|
+
Multi-agent layouts only (NOX_AGENTS_DIR); on a standalone install there is nothing to read
|
|
254
257
|
nox-mem-api — start HTTP API on $NOX_API_PORT (default 18802)
|
|
255
258
|
nox-mem-mcp — start MCP server over stdio (22 tools, incl. nox_mem_answer and nox_mem_get, for agents)
|
|
256
259
|
nox-mem doctor — health check (core + optional integrations)
|
package/dist/kg-llm.js
CHANGED
|
@@ -82,7 +82,7 @@ export function normalizeRelationReason(raw, relationType) {
|
|
|
82
82
|
// ─── Fast-path regex (PT-BR) ────────────────────────────────────────────────
|
|
83
83
|
//
|
|
84
84
|
// Detecta entidades óbvias sem LLM. Se ≥3 encontradas, pula Gemini.
|
|
85
|
-
// Patterns calibrados para
|
|
85
|
+
// Patterns calibrados para documentos de negócio em PT-BR.
|
|
86
86
|
const RE_VALUE_BRL = /R\$\s?\d[\d\.,]*(?:\s?(?:mil|milh[ãa]o|milh[õo]es|bi|bilh[ãa]o|k|m|b))?/gi;
|
|
87
87
|
const RE_VALUE_USD = /US?\$\s?\d[\d\.,]*(?:\s?(?:k|m|b|million|thousand|billion))?/gi;
|
|
88
88
|
const RE_VALUE_EUR = /€\s?\d[\d\.,]*/gi;
|
package/dist/session-distill.js
CHANGED
|
@@ -133,6 +133,31 @@ export function listUnprocessedSessions(db, agentIds, lookbackDays) {
|
|
|
133
133
|
sessions.sort((a, b) => a.mtimeMs - b.mtimeMs || a.sessionKey.localeCompare(b.sessionKey));
|
|
134
134
|
return sessions;
|
|
135
135
|
}
|
|
136
|
+
/** A session with fewer messages than this holds only init events: nothing to distill. */
|
|
137
|
+
export const MIN_SESSION_MESSAGES = 3;
|
|
138
|
+
/**
|
|
139
|
+
* Walks `pending` in order and splits it into the sessions to distill now (at most `max`, each
|
|
140
|
+
* with its messages already read) and the short ones, which are logged as done without counting
|
|
141
|
+
* against `max`. Reading stops once `max` sessions are taken; `left` is how many were not read.
|
|
142
|
+
*
|
|
143
|
+
* The budget used to be cut before the short sessions were set aside, so they spent it. Measured
|
|
144
|
+
* on one deployment (nightly run, 1-day lookback, max 50): 43 to 48 of the 50 sessions taken each
|
|
145
|
+
* night since 2026-11-10 were short, 2 to 7 were distilled, and the ~35 left over aged out of the
|
|
146
|
+
* lookback before the next run.
|
|
147
|
+
*/
|
|
148
|
+
export function partitionPending(pending, max, read) {
|
|
149
|
+
const take = [];
|
|
150
|
+
const short = [];
|
|
151
|
+
let i = 0;
|
|
152
|
+
for (; i < pending.length && take.length < max; i++) {
|
|
153
|
+
const messages = read(pending[i]);
|
|
154
|
+
if (messages.length < MIN_SESSION_MESSAGES)
|
|
155
|
+
short.push({ session: pending[i], count: messages.length });
|
|
156
|
+
else
|
|
157
|
+
take.push({ session: pending[i], messages });
|
|
158
|
+
}
|
|
159
|
+
return { take, short, left: pending.length - i };
|
|
160
|
+
}
|
|
136
161
|
// ─── Message extraction ───────────────────────────────────────────────────────
|
|
137
162
|
export function extractMessages(sessionFile) {
|
|
138
163
|
const messages = [];
|
|
@@ -288,30 +313,28 @@ export async function distillSessions(options = {}) {
|
|
|
288
313
|
blockOutcomes: {},
|
|
289
314
|
};
|
|
290
315
|
const pending = listUnprocessedSessions(db, agentIds, lookbackDays);
|
|
291
|
-
const sessions = pending
|
|
292
|
-
|
|
316
|
+
const { take: sessions, short, left } = partitionPending(pending, maxSessionsPerRun, (s) => extractMessages(s.sessionFile));
|
|
317
|
+
// Short sessions (just init events) are logged as done and do not count against the budget.
|
|
318
|
+
for (const { session, count } of short) {
|
|
319
|
+
stats.skippedSessions++;
|
|
320
|
+
if (!dryRun) {
|
|
321
|
+
db.prepare("INSERT OR IGNORE INTO session_distill_log (session_key, agent, chunks_extracted, message_count) VALUES (?, ?, 0, ?)").run(session.sessionKey, session.agentId, count);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (left > 0) {
|
|
293
325
|
// A full list on every run is the backlog signal: say how much is left, in the log a
|
|
294
326
|
// scheduled job keeps, instead of leaving it to be found by a census.
|
|
295
|
-
console.log(`[DISTILL] Backlog: ${pending.length} unprocessed in the lookback, taking the ${sessions.length} oldest; ${
|
|
327
|
+
console.log(`[DISTILL] Backlog: ${pending.length} unprocessed in the lookback; ${short.length} short logged, taking the ${sessions.length} oldest; ${left} left for the next run`);
|
|
296
328
|
}
|
|
297
329
|
if (sessions.length === 0) {
|
|
298
|
-
console.log("[DISTILL] No unprocessed sessions found");
|
|
330
|
+
console.log(short.length ? `[DISTILL] ${short.length} short sessions logged, none to distill` : "[DISTILL] No unprocessed sessions found");
|
|
299
331
|
recordOutcomes(dryRun, agentIds, lookbackDays, pending.length, stats);
|
|
300
332
|
return stats;
|
|
301
333
|
}
|
|
302
|
-
console.log(`[DISTILL] Processing ${sessions.length} sessions (lookback: ${lookbackDays}d)`);
|
|
334
|
+
console.log(`[DISTILL] Processing ${sessions.length} sessions (lookback: ${lookbackDays}d; ${short.length} short logged)`);
|
|
303
335
|
// Group messages into blocks of ~2000 chars for the LLM
|
|
304
336
|
const BLOCK_SIZE = 2000;
|
|
305
|
-
for (const { agentId,
|
|
306
|
-
const messages = extractMessages(sessionFile);
|
|
307
|
-
if (messages.length < 3) {
|
|
308
|
-
// Skip tiny sessions (just session init events)
|
|
309
|
-
stats.skippedSessions++;
|
|
310
|
-
if (!dryRun) {
|
|
311
|
-
db.prepare("INSERT OR IGNORE INTO session_distill_log (session_key, agent, chunks_extracted, message_count) VALUES (?, ?, 0, ?)").run(sessionKey, agentId, messages.length);
|
|
312
|
-
}
|
|
313
|
-
continue;
|
|
314
|
-
}
|
|
337
|
+
for (const { session: { agentId, sessionKey }, messages } of sessions) {
|
|
315
338
|
stats.messagesRead += messages.length;
|
|
316
339
|
// Build conversation text, apply noise filter
|
|
317
340
|
const conversationLines = messages
|