nebula-memory-mcp 1.2.4 → 1.2.5
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/mcp-server.mjs +1 -1
- package/memory/store.cjs +30 -6
- package/package.json +1 -1
package/mcp-server.mjs
CHANGED
package/memory/store.cjs
CHANGED
|
@@ -581,6 +581,14 @@ function isPidAlive(pid) {
|
|
|
581
581
|
}
|
|
582
582
|
|
|
583
583
|
/** 追加一行(append 只写一行,崩溃最多丢最后一行,读入时会当坏行跳过) */
|
|
584
|
+
function fileBytes(file) {
|
|
585
|
+
try {
|
|
586
|
+
return fs.statSync(file).size;
|
|
587
|
+
} catch {
|
|
588
|
+
return 0;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
|
|
584
592
|
function appendLine(file, obj) {
|
|
585
593
|
// 返回这一行在文件里的字节区间,供薄索引记录原文位置(懒加载用)。
|
|
586
594
|
// 先取文件长度当偏移:单进程追加写,长度即下一次写入的起点。
|
|
@@ -598,8 +606,8 @@ function appendLine(file, obj) {
|
|
|
598
606
|
} finally {
|
|
599
607
|
fs.closeSync(fd);
|
|
600
608
|
}
|
|
601
|
-
// len 去掉行尾换行,只覆盖 JSON
|
|
602
|
-
return { off, len: len - 1 };
|
|
609
|
+
// len 去掉行尾换行,只覆盖 JSON 本体;end 是下一行的起点字节位置
|
|
610
|
+
return { off, len: len - 1, end: off + len };
|
|
603
611
|
}
|
|
604
612
|
|
|
605
613
|
/** 人类可读的时间差(renderContext 用) */
|
|
@@ -681,6 +689,11 @@ class NebulaMemory {
|
|
|
681
689
|
|
|
682
690
|
this._nodeLines = 0;
|
|
683
691
|
this._edgeLines = 0;
|
|
692
|
+
// 本实例「已经读到/写到」的 jsonl 字节边界。
|
|
693
|
+
// 写薄索引时用它而不是 fs.statSync:否则持有旧视图的进程会写出
|
|
694
|
+
// 「内容少、大小新」的假自洽索引,把别人新写的记录静默吞掉(2026-11-30 踩到)。
|
|
695
|
+
this._nodeBytes = 0;
|
|
696
|
+
this._edgeBytes = 0;
|
|
684
697
|
this._badLines = 0;
|
|
685
698
|
this._indexDirty = true;
|
|
686
699
|
this._indexMeta = null;
|
|
@@ -1819,6 +1832,7 @@ class NebulaMemory {
|
|
|
1819
1832
|
offsets.set(id, { off, len });
|
|
1820
1833
|
});
|
|
1821
1834
|
this._nodeLines = res.lines;
|
|
1835
|
+
this._nodeBytes = fileBytes(this.fileNodes);
|
|
1822
1836
|
this._badLines += res.bad + invalid;
|
|
1823
1837
|
for (const [id, raw] of this._raw) {
|
|
1824
1838
|
if (raw.deleted) continue; // 软删记录留在 _raw 里,不进索引
|
|
@@ -1871,6 +1885,7 @@ class NebulaMemory {
|
|
|
1871
1885
|
this.edgeMap.set(key, { a: lo, b: hi, w, kind, lastFired, fireCount });
|
|
1872
1886
|
});
|
|
1873
1887
|
this._edgeLines = res.lines;
|
|
1888
|
+
this._edgeBytes = fileBytes(this.fileEdges);
|
|
1874
1889
|
this._badLines += res.bad + invalid;
|
|
1875
1890
|
// 端点不存在的边(对端被 forget / 或压缩前残留)不参与内存图
|
|
1876
1891
|
for (const [key, e] of this.edgeMap) {
|
|
@@ -2022,6 +2037,8 @@ class NebulaMemory {
|
|
|
2022
2037
|
this._tombstones = num(payload.tombstones, 0);
|
|
2023
2038
|
this._nodeLines = num(payload.nodeLines, 0);
|
|
2024
2039
|
this._edgeLines = num(payload.edgeLines, 0);
|
|
2040
|
+
this._nodeBytes = num(payload.nodeBytes, 0);
|
|
2041
|
+
this._edgeBytes = num(payload.edgeBytes, 0);
|
|
2025
2042
|
this._badLines = 0;
|
|
2026
2043
|
|
|
2027
2044
|
this.postings.clear();
|
|
@@ -2311,8 +2328,10 @@ class NebulaMemory {
|
|
|
2311
2328
|
thinVersion: THIN_VERSION,
|
|
2312
2329
|
builtAt: new Date().toISOString(),
|
|
2313
2330
|
dir: this.dir,
|
|
2314
|
-
|
|
2315
|
-
|
|
2331
|
+
// 用本实例已知边界,而不是 fs.statSync:文件可能被别的进程追加过,
|
|
2332
|
+
// 现取大小会让薄索引「内容旧、大小新」,校验永远通过、数据永远丢(2026-11-30)。
|
|
2333
|
+
nodeBytes: this._nodeBytes || sizeOf(this.fileNodes),
|
|
2334
|
+
edgeBytes: this._edgeBytes || sizeOf(this.fileEdges),
|
|
2316
2335
|
nodeLines: this._nodeLines,
|
|
2317
2336
|
edgeLines: this._edgeLines,
|
|
2318
2337
|
tombstones: this._countTombstones(),
|
|
@@ -2412,6 +2431,7 @@ class NebulaMemory {
|
|
|
2412
2431
|
_appendNode(n) {
|
|
2413
2432
|
const rec = this._publicNode(n);
|
|
2414
2433
|
const pos = appendLine(this.fileNodes, rec);
|
|
2434
|
+
if (pos) this._nodeBytes = pos.end;
|
|
2415
2435
|
// 记下这一行的位置:薄索引写盘时要用它做原文懒加载
|
|
2416
2436
|
if (pos) {
|
|
2417
2437
|
Object.defineProperty(n, '_off', { value: pos.off, writable: true, enumerable: false, configurable: true });
|
|
@@ -2447,7 +2467,8 @@ class NebulaMemory {
|
|
|
2447
2467
|
|
|
2448
2468
|
/** 追加一行边记录(同一对端点后写覆盖先写) */
|
|
2449
2469
|
_saveEdge(edge) {
|
|
2450
|
-
appendLine(this.fileEdges, { ...edge, ts: Date.now() });
|
|
2470
|
+
const pos = appendLine(this.fileEdges, { ...edge, ts: Date.now() });
|
|
2471
|
+
if (pos) this._edgeBytes = pos.end;
|
|
2451
2472
|
this._edgeLines++;
|
|
2452
2473
|
this._writesSinceIndex++;
|
|
2453
2474
|
}
|
|
@@ -2468,7 +2489,8 @@ class NebulaMemory {
|
|
|
2468
2489
|
if (ma) ma.delete(edge.b);
|
|
2469
2490
|
const mb = this.adj.get(edge.b);
|
|
2470
2491
|
if (mb) mb.delete(edge.a);
|
|
2471
|
-
appendLine(this.fileEdges, { a: edge.a, b: edge.b, deleted: true, ts: Date.now() });
|
|
2492
|
+
const pos = appendLine(this.fileEdges, { a: edge.a, b: edge.b, deleted: true, ts: Date.now() });
|
|
2493
|
+
if (pos) this._edgeBytes = pos.end;
|
|
2472
2494
|
this._edgeLines++;
|
|
2473
2495
|
this._writesSinceIndex++;
|
|
2474
2496
|
}
|
|
@@ -2671,6 +2693,7 @@ class NebulaMemory {
|
|
|
2671
2693
|
}
|
|
2672
2694
|
atomicWrite(this.fileNodes, lines.length ? lines.join('\n') + '\n' : '');
|
|
2673
2695
|
this._nodeLines = lines.length;
|
|
2696
|
+
this._nodeBytes = off; // off 已经累加到「全部重写后的总字节数」
|
|
2674
2697
|
this._thinDirty = true;
|
|
2675
2698
|
this._log('info', `compacted nodes.jsonl -> ${lines.length} lines`);
|
|
2676
2699
|
}
|
|
@@ -2680,6 +2703,7 @@ class NebulaMemory {
|
|
|
2680
2703
|
for (const e of this.edgeMap.values()) lines.push(JSON.stringify(e));
|
|
2681
2704
|
atomicWrite(this.fileEdges, lines.length ? lines.join('\n') + '\n' : '');
|
|
2682
2705
|
this._edgeLines = lines.length;
|
|
2706
|
+
this._edgeBytes = sizeOf(this.fileEdges);
|
|
2683
2707
|
this._log('info', `compacted edges.jsonl -> ${lines.length} lines`);
|
|
2684
2708
|
}
|
|
2685
2709
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nebula-memory-mcp",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
4
4
|
"mcpName": "io.github.yb-zhai/nebula-memory",
|
|
5
5
|
"description": "Zero-dependency local Agent memory MCP Server (stdio JSON-RPC). Works offline, no API keys, no database. Exposes remember/recall/stats/forget to Claude Desktop, Cursor, ChatGPT and any MCP client.",
|
|
6
6
|
"type": "module",
|