nox-mem 3.10.0 → 3.10.1
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/ingest-entity.js +3 -3
- package/dist/ingest.js +3 -3
- package/dist/lib/ingest-router.js +2 -3
- package/dist/lib/tombstone.js +6 -7
- package/dist/lib/workspace.js +36 -2
- package/dist/reindex.js +3 -3
- package/dist/retention.js +1 -0
- package/dist/session-distill.js +7 -2
- package/dist/watch.js +4 -4
- package/package.json +1 -1
package/dist/ingest-entity.js
CHANGED
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
//
|
|
23
23
|
// Each file produces N+2 chunks: 1 frontmatter + 1 compiled + N timeline entries.
|
|
24
24
|
import { existsSync, readFileSync } from "fs";
|
|
25
|
-
import {
|
|
25
|
+
import { resolve } from "path";
|
|
26
26
|
import { getDb } from "./db.js";
|
|
27
27
|
import { syncFileChunks } from "./lib/chunk-sync.js";
|
|
28
28
|
import { getInitialTier } from "./tier-manager.js";
|
|
29
29
|
import { resolveRetention } from "./retention.js";
|
|
30
30
|
import { inferPain, inferImportance } from "./salience.js";
|
|
31
31
|
import { redact as _redactPrivacy } from "./privacy/filter.js";
|
|
32
|
-
import { workspaceRoot } from "./lib/workspace.js";
|
|
32
|
+
import { workspaceRoot, sourceKeyFor } from "./lib/workspace.js";
|
|
33
33
|
const WORKSPACE = workspaceRoot();
|
|
34
34
|
/**
|
|
35
35
|
* Section boost values by section type. Multiplicative in search ranking but
|
|
@@ -122,7 +122,7 @@ function parseSimpleYaml(raw) {
|
|
|
122
122
|
* `compiled == frontmatter` invariant (CLAUDE.md rule 6) holds per file.
|
|
123
123
|
*/
|
|
124
124
|
export function ingestEntitySync(db, filePath) {
|
|
125
|
-
const relPath =
|
|
125
|
+
const relPath = sourceKeyFor(filePath, WORKSPACE);
|
|
126
126
|
const content = readFileSync(filePath, "utf-8");
|
|
127
127
|
const entity = parseEntityFile(content);
|
|
128
128
|
if (!entity) {
|
package/dist/ingest.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "fs";
|
|
2
|
-
import {
|
|
2
|
+
import { resolve } from "path";
|
|
3
3
|
import { getDb } from "./db.js";
|
|
4
4
|
import { syncFileChunks } from "./lib/chunk-sync.js";
|
|
5
5
|
import { ensureTombstoneTable, resolveTombstoneOnIngest } from "./lib/tombstone.js";
|
|
@@ -7,7 +7,7 @@ import { getInitialTier, getInitialImportance } from "./tier-manager.js";
|
|
|
7
7
|
import { resolveRetention } from "./retention.js";
|
|
8
8
|
import { inferPain, inferImportance } from "./salience.js";
|
|
9
9
|
import { redact } from "./privacy/filter.js";
|
|
10
|
-
import { workspaceRoot } from "./lib/workspace.js";
|
|
10
|
+
import { workspaceRoot, sourceKeyFor } from "./lib/workspace.js";
|
|
11
11
|
const WORKSPACE = workspaceRoot();
|
|
12
12
|
const TYPE_MAP = {
|
|
13
13
|
"memory/decisions.md": "decision",
|
|
@@ -180,7 +180,7 @@ const EMPTY = { chunks: 0, inserted: [], kept: 0, deleted: 0, adopted: 0 };
|
|
|
180
180
|
* disk again, so a tombstone left when it was deleted is resolved (2026-10-15).
|
|
181
181
|
*/
|
|
182
182
|
export function ingestMarkdownSync(db, filePath) {
|
|
183
|
-
const relPath =
|
|
183
|
+
const relPath = sourceKeyFor(filePath, WORKSPACE);
|
|
184
184
|
// A2 (2026-04-25): entity routing lives in lib/ingest-router.ts — single dispatch.
|
|
185
185
|
let content = readFileSync(filePath, "utf-8");
|
|
186
186
|
if (!content.trim()) {
|
|
@@ -8,10 +8,9 @@
|
|
|
8
8
|
//
|
|
9
9
|
// Defesa em camadas: ingestFile() ainda tem guard interno pra entity files (caso
|
|
10
10
|
// algum legacy caller pule o router). Mas o router é o caminho canônico daqui em diante.
|
|
11
|
-
import { relative } from "node:path";
|
|
12
11
|
import { ingestFile, ingestMarkdownSync } from "../ingest.js";
|
|
13
12
|
import { ingestEntityFile, ingestEntitySync } from "../ingest-entity.js";
|
|
14
|
-
import { workspaceRoot } from "./workspace.js";
|
|
13
|
+
import { workspaceRoot, sourceKeyFor } from "./workspace.js";
|
|
15
14
|
const WORKSPACE = workspaceRoot();
|
|
16
15
|
const diffOf = (r) => ({
|
|
17
16
|
inserted: r.inserted, kept: r.kept, deleted: r.deleted, adopted: r.adopted,
|
|
@@ -21,7 +20,7 @@ const diffOf = (r) => ({
|
|
|
21
20
|
* arquivo quando adicionar novo tipo (ex: "pdf-text-layer", "fathom-transcript").
|
|
22
21
|
*/
|
|
23
22
|
export function detectIngestKind(filePath) {
|
|
24
|
-
const relPath =
|
|
23
|
+
const relPath = sourceKeyFor(filePath, WORKSPACE);
|
|
25
24
|
if (relPath.startsWith("memory/entities/") && filePath.endsWith(".md"))
|
|
26
25
|
return "entity";
|
|
27
26
|
if (relPath.startsWith("graphify-out/") || relPath.includes("/graphify-out/"))
|
package/dist/lib/tombstone.js
CHANGED
|
@@ -23,19 +23,18 @@
|
|
|
23
23
|
// The table is created lazily (like ensureVecTable) instead of by a schema
|
|
24
24
|
// bump: the npm and production lineages number their schema versions
|
|
25
25
|
// differently, and a CREATE TABLE IF NOT EXISTS lands the same on both.
|
|
26
|
-
import {
|
|
27
|
-
import { workspaceRoot } from "./workspace.js";
|
|
26
|
+
import { sourceKeyFor } from "./workspace.js";
|
|
28
27
|
/**
|
|
29
|
-
* The `source_file` key ingest writes for `path
|
|
30
|
-
*
|
|
31
|
-
* argument against the cwd. Every command that names
|
|
32
|
-
* on this same key, or it silently misses the chunks.
|
|
28
|
+
* The `source_file` key ingest writes for `path` (`sourceKeyFor` in workspace.ts,
|
|
29
|
+
* the one definition ingest, the router, the entity ingest, watch and reindex
|
|
30
|
+
* use); a relative argument resolves against the cwd. Every command that names
|
|
31
|
+
* a file by path has to land on this same key, or it silently misses the chunks.
|
|
33
32
|
*
|
|
34
33
|
* On a standalone install nothing lives under the default workspace, so keys
|
|
35
34
|
* start with `../`; that is the key, not an error.
|
|
36
35
|
*/
|
|
37
36
|
export function sourceKey(path) {
|
|
38
|
-
return
|
|
37
|
+
return sourceKeyFor(path);
|
|
39
38
|
}
|
|
40
39
|
/**
|
|
41
40
|
* What a CLI argument names: either a key exactly as `nox-mem tombstones` lists
|
package/dist/lib/workspace.js
CHANGED
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
* watched nothing and `reindex` refused. Schema v20 rewrites those keys
|
|
18
18
|
* (`migrateStandaloneKeys` in db.ts).
|
|
19
19
|
*/
|
|
20
|
-
import { existsSync } from "fs";
|
|
20
|
+
import { existsSync, realpathSync } from "fs";
|
|
21
21
|
import { homedir } from "os";
|
|
22
|
-
import { join } from "path";
|
|
22
|
+
import { basename, dirname, join, relative, resolve } from "path";
|
|
23
23
|
export const ORIGIN_WORKSPACE = "/root/.openclaw/workspace";
|
|
24
24
|
export function standaloneWorkspace() {
|
|
25
25
|
return join(homedir(), ".nox-mem");
|
|
@@ -34,3 +34,37 @@ export function workspaceRootWithSource(env = process.env, exists = existsSync)
|
|
|
34
34
|
export function workspaceRoot() {
|
|
35
35
|
return workspaceRootWithSource().root;
|
|
36
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* `path` with every symlink resolved, also when the file itself no longer exists
|
|
39
|
+
* (a deleted note still has to land on the key it was stored under): the deepest
|
|
40
|
+
* existing ancestor is resolved and the missing tail is appended as written.
|
|
41
|
+
*/
|
|
42
|
+
export function canonicalPath(path) {
|
|
43
|
+
const abs = resolve(path);
|
|
44
|
+
const tail = [];
|
|
45
|
+
let head = abs;
|
|
46
|
+
for (;;) {
|
|
47
|
+
try {
|
|
48
|
+
const real = realpathSync(head);
|
|
49
|
+
return tail.length ? join(real, ...tail.reverse()) : real;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
const parent = dirname(head);
|
|
53
|
+
if (parent === head)
|
|
54
|
+
return abs;
|
|
55
|
+
tail.push(basename(head));
|
|
56
|
+
head = parent;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The `source_file` key for `path`, relative to the workspace root. Both sides
|
|
62
|
+
* go through `canonicalPath`, so a file reached through a symlink gets the same
|
|
63
|
+
* key as the file reached directly. Until 3.10.1 the key was `relative()` of
|
|
64
|
+
* the path as given: on the origin VPS `/root/.openclaw/agents/<a>` is a symlink
|
|
65
|
+
* to `<workspace>/agents/<a>`, and a job that ingested through the link stored
|
|
66
|
+
* the same note a second time under `../agents/<a>/…` (83 sources, 2026-11-11).
|
|
67
|
+
*/
|
|
68
|
+
export function sourceKeyFor(path, root = workspaceRoot()) {
|
|
69
|
+
return relative(canonicalPath(root), canonicalPath(path));
|
|
70
|
+
}
|
package/dist/reindex.js
CHANGED
|
@@ -39,9 +39,9 @@ import { routeIngestSync } from "./lib/ingest-router.js";
|
|
|
39
39
|
import { ensureTombstoneTable, tombstoneFile } from "./lib/tombstone.js";
|
|
40
40
|
import { existsSync, readdirSync } from "fs";
|
|
41
41
|
import { createHash } from "crypto";
|
|
42
|
-
import { join,
|
|
42
|
+
import { join, resolve } from "path";
|
|
43
43
|
import { ReindexWipeDetectedError, ReindexSourceMissingError, ReindexWorkspaceMismatchError, MIN_RETENTION_RATIO } from "./reindex-errors.js";
|
|
44
|
-
import { workspaceRoot, workspaceRootWithSource } from "./lib/workspace.js";
|
|
44
|
+
import { workspaceRoot, workspaceRootWithSource, sourceKeyFor } from "./lib/workspace.js";
|
|
45
45
|
import { DEFAULT_STANDALONE_DB_PATH } from "./lib/db-path.js";
|
|
46
46
|
export { ReindexWipeDetectedError, ReindexSourceMissingError, ReindexWorkspaceMismatchError } from "./reindex-errors.js";
|
|
47
47
|
const WORKSPACE = workspaceRoot();
|
|
@@ -164,7 +164,7 @@ async function _reindexImpl() {
|
|
|
164
164
|
// Same scan as assertReindexSource — one definition of "the source".
|
|
165
165
|
const { memoryFiles, sharedFiles } = collectReindexFiles();
|
|
166
166
|
const allFiles = [...memoryFiles, ...sharedFiles];
|
|
167
|
-
const roots = reindexRoots().map((r) =>
|
|
167
|
+
const roots = reindexRoots().map((r) => sourceKeyFor(r, WORKSPACE) + "/");
|
|
168
168
|
const fileErrors = [];
|
|
169
169
|
const t = { chunks: 0, kept: 0, inserted: 0, deleted: 0, adopted: 0, tombstoned: 0 };
|
|
170
170
|
let retainedDistinct = preDistinct;
|
package/dist/retention.js
CHANGED
|
@@ -24,6 +24,7 @@ export const RETENTION_BY_TYPE = {
|
|
|
24
24
|
digest: 180, // digest consolida várias sessões
|
|
25
25
|
pending: 30, // se 30d sem resolver, escala pra review
|
|
26
26
|
graph_node: 60, // repos externos indexados via graphify — research-like, decay rápido
|
|
27
|
+
distilled: null, // never — escolha explícita (DECISIONS 27/10 #3); session-distill grava NULL
|
|
27
28
|
other: 90, // default
|
|
28
29
|
};
|
|
29
30
|
export const DEFAULT_RETENTION_DAYS = 90;
|
package/dist/session-distill.js
CHANGED
|
@@ -348,9 +348,14 @@ export async function distillSessions(options = {}) {
|
|
|
348
348
|
const chunkType = "distilled";
|
|
349
349
|
const tier = memory.importance >= 0.8 ? "working" : "peripheral";
|
|
350
350
|
const today = new Date().toISOString().split("T")[0];
|
|
351
|
+
// retention_days = NULL is a choice, not an omission: distilled memory never decays
|
|
352
|
+
// (salience reads NULL as never-decay, so recency stays 1.0). Measured 2026-10-27 before
|
|
353
|
+
// choosing: a 90-day window would move a distilled chunk's median salience by -0.082 and
|
|
354
|
+
// archive nothing, which does not justify moving the served ranking. Listed explicitly so
|
|
355
|
+
// that no backfill or default can turn it into 90 days by accident (DECISIONS 27/10 #3).
|
|
351
356
|
db.prepare(`
|
|
352
|
-
INSERT INTO chunks (source_file, chunk_text, chunk_type, source_date, metadata, tier, importance)
|
|
353
|
-
VALUES (?, ?, ?, ?, ?, ?,
|
|
357
|
+
INSERT INTO chunks (source_file, chunk_text, chunk_type, source_date, metadata, tier, importance, retention_days)
|
|
358
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, NULL)
|
|
354
359
|
`).run(`sessions/${agentId}/${sessionKey}`, `[${memory.category}|${agentId}] ${memory.text}`, chunkType, today, JSON.stringify({ category: memory.category, source_agent: agentId, session: sessionKey }), tier, memory.importance);
|
|
355
360
|
stats.memoriesIngested++;
|
|
356
361
|
sessionExtracted++;
|
package/dist/watch.js
CHANGED
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
* Skips: binary files, .db, .json session files, tmp files.
|
|
9
9
|
*/
|
|
10
10
|
import { watch, statSync, existsSync, readdirSync } from "fs";
|
|
11
|
-
import { resolve, extname
|
|
11
|
+
import { resolve, extname } from "path";
|
|
12
12
|
import { routeIngest } from "./lib/ingest-router.js";
|
|
13
13
|
import { getDb } from "./db.js";
|
|
14
14
|
import { tombstoneFile, tombstonePrefix } from "./lib/tombstone.js";
|
|
15
|
-
import { workspaceRoot } from "./lib/workspace.js";
|
|
15
|
+
import { workspaceRoot, sourceKeyFor } from "./lib/workspace.js";
|
|
16
16
|
const WORKSPACE = workspaceRoot();
|
|
17
17
|
// NOX_WATCH_DIRS: comma-separated list of ABSOLUTE paths to watch.
|
|
18
18
|
// If unset, falls back to the default OpenClaw workspace layout below.
|
|
@@ -66,7 +66,7 @@ function shouldProcess(filepath) {
|
|
|
66
66
|
const debounceMap = new Map();
|
|
67
67
|
const DEBOUNCE_MS = 2000;
|
|
68
68
|
function tombstoneMissing(filepath) {
|
|
69
|
-
const rel =
|
|
69
|
+
const rel = sourceKeyFor(filepath, WORKSPACE);
|
|
70
70
|
if (rel.startsWith(".."))
|
|
71
71
|
return; // NOX_WATCH_DIRS outside the workspace: no source_file to match
|
|
72
72
|
try {
|
|
@@ -137,7 +137,7 @@ function debounceTombstoneDir(dirpath) {
|
|
|
137
137
|
debounceMap.delete(key);
|
|
138
138
|
if (existsSync(dirpath))
|
|
139
139
|
return;
|
|
140
|
-
const rel =
|
|
140
|
+
const rel = sourceKeyFor(dirpath, WORKSPACE);
|
|
141
141
|
if (rel.startsWith("..") || rel === "")
|
|
142
142
|
return;
|
|
143
143
|
try {
|