@imliulian/dsh-zeromem 0.1.0 → 0.2.0
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/CHANGELOG.md +10 -0
- package/NOTICE +17 -0
- package/README.md +35 -10
- package/README.zh.md +35 -10
- package/assets/panel.js +110 -4
- package/bin/dsh-zeromem.mjs +187 -0
- package/lib/contracts.mjs +94 -2
- package/lib/expiry.mjs +105 -1
- package/lib/hooks.mjs +8 -2
- package/lib/index.mjs +3 -1
- package/lib/llm.mjs +6 -2
- package/lib/memory.mjs +177 -7
- package/lib/portability.mjs +819 -0
- package/lib/store.mjs +268 -28
- package/lib/tools.mjs +60 -3
- package/lib/web.mjs +86 -8
- package/package.json +8 -4
package/lib/web.mjs
CHANGED
|
@@ -421,15 +421,93 @@ export function mountWebServer(ctx, engine) {
|
|
|
421
421
|
const q = qs.get("q") || "";
|
|
422
422
|
const ns = qs.get("ns") || null;
|
|
423
423
|
const limit = Math.max(1, Math.min(Number(qs.get("limit") || 50) || 50, 100));
|
|
424
|
+
const occurredFrom = qs.get("occurred_from") || null;
|
|
425
|
+
const occurredTo = qs.get("occurred_to") || null;
|
|
426
|
+
const rawIncSup = qs.get("include_superseded");
|
|
427
|
+
const includeSuperseded =
|
|
428
|
+
rawIncSup === null ? true : !["0", "false", "no", "off"].includes(rawIncSup.trim().toLowerCase());
|
|
424
429
|
const t0 = Date.now();
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
430
|
+
try {
|
|
431
|
+
// Always disable adaptive pruning in the human workbench browse view so users see complete matches
|
|
432
|
+
const items = engine.recall(q, {
|
|
433
|
+
ns,
|
|
434
|
+
limit,
|
|
435
|
+
adaptive: false,
|
|
436
|
+
occurredFrom,
|
|
437
|
+
occurredTo,
|
|
438
|
+
includeSuperseded,
|
|
439
|
+
});
|
|
440
|
+
sendJson(res, 200, {
|
|
441
|
+
ok: true,
|
|
442
|
+
count: items.length,
|
|
443
|
+
elapsed_ms: Date.now() - t0,
|
|
444
|
+
items,
|
|
445
|
+
});
|
|
446
|
+
} catch (err) {
|
|
447
|
+
const msg = String(err?.message || err);
|
|
448
|
+
const status = msg.startsWith("invalid-occurred-") ? 400 : 500;
|
|
449
|
+
sendJson(res, status, { ok: false, error: msg.slice(0, 240) });
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
addRoute("/dsh-zeromem/api/export.md", async (req, res) => {
|
|
454
|
+
const method = String(req.method || "GET").toUpperCase();
|
|
455
|
+
if (method !== "GET") {
|
|
456
|
+
sendJson(res, 405, { ok: false, error: "GET required" });
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
const qs = parseQuery(req.url);
|
|
460
|
+
const ns = qs.get("ns") || null;
|
|
461
|
+
const occurredFrom = qs.get("occurred_from") || null;
|
|
462
|
+
const occurredTo = qs.get("occurred_to") || null;
|
|
463
|
+
const rawIncSup = qs.get("include_superseded");
|
|
464
|
+
const includeSuperseded =
|
|
465
|
+
rawIncSup === null ? true : !["0", "false", "no", "off"].includes(rawIncSup.trim().toLowerCase());
|
|
466
|
+
const includeEvicted = ["1", "true", "yes"].includes(String(qs.get("include_evicted") || "").toLowerCase());
|
|
467
|
+
const frontmatter = !["0", "false", "no"].includes(String(qs.get("frontmatter") || "1").toLowerCase());
|
|
468
|
+
const asDownload = ["1", "true"].includes(String(qs.get("download") || "").toLowerCase());
|
|
469
|
+
|
|
470
|
+
try {
|
|
471
|
+
const exp = engine.exportMarkdown({
|
|
472
|
+
ns,
|
|
473
|
+
occurredFrom,
|
|
474
|
+
occurredTo,
|
|
475
|
+
includeSuperseded,
|
|
476
|
+
includeEvicted,
|
|
477
|
+
frontmatter,
|
|
478
|
+
});
|
|
479
|
+
const stamp = new Date().toISOString().slice(0, 10);
|
|
480
|
+
const safeNs = ns ? `-${String(ns).replace(/[^A-Za-z0-9._-]+/g, "_").slice(0, 32)}` : "";
|
|
481
|
+
const filename = `zeromem-export${safeNs}-${stamp}.md`;
|
|
482
|
+
const headers = {
|
|
483
|
+
"Content-Type": "text/markdown; charset=utf-8",
|
|
484
|
+
"Cache-Control": "no-store",
|
|
485
|
+
"X-Content-Type-Options": "nosniff",
|
|
486
|
+
};
|
|
487
|
+
if (asDownload) {
|
|
488
|
+
headers["Content-Disposition"] = `attachment; filename="${filename}"`;
|
|
489
|
+
}
|
|
490
|
+
res.writeHead(200, headers);
|
|
491
|
+
res.end(exp.markdown || "");
|
|
492
|
+
} catch (err) {
|
|
493
|
+
const msg = String(err?.message || err);
|
|
494
|
+
const status = msg.startsWith("invalid-occurred-") ? 400 : 500;
|
|
495
|
+
sendJson(res, status, { ok: false, error: msg.slice(0, 240) });
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
addRoute("/dsh-zeromem/api/backup", async (req, res) => {
|
|
500
|
+
const method = String(req.method || "POST").toUpperCase();
|
|
501
|
+
if (method !== "POST") {
|
|
502
|
+
sendJson(res, 405, { ok: false, error: "POST required" });
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
const body = await readJsonBody(req);
|
|
506
|
+
const writeSha256 = body?.sha256 !== undefined ? Boolean(body.sha256) : true;
|
|
507
|
+
const verify = body?.verify !== undefined ? Boolean(body.verify) : true;
|
|
508
|
+
// Always write into the fixed local <db_dir>/backups/ folder (never accept arbitrary client paths)
|
|
509
|
+
const receipt = await engine.backup(null, { writeSha256, verify });
|
|
510
|
+
sendJson(res, 200, { ok: true, receipt });
|
|
433
511
|
});
|
|
434
512
|
|
|
435
513
|
addRoute("/dsh-zeromem/api/document", async (req, res) => {
|
package/package.json
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imliulian/dsh-zeromem",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "ZeroMem (零忆) local evidence-grounded memory system for DeepSeek Harness — single-file node:sqlite + CJK/EN FTS5 (<1ms recall), pre-write admission verification, credential redaction, until: expiry, SHA-256 lossless restore, local Ollama & OpenAI-compatible API support.",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "ZeroMem (零忆) local evidence-grounded memory system for DeepSeek Harness — single-file node:sqlite + CJK/EN FTS5 (<1ms recall), timeline supersession & date-range filtering, read-only Markdown export, SQLite Online Backup, pre-write admission verification, credential redaction, until: expiry, SHA-256 lossless restore, local Ollama & OpenAI-compatible API support.",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"author": "IMLIULIAN (ZeroZoneX)",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "./lib/index.mjs",
|
|
9
|
+
"bin": {
|
|
10
|
+
"dsh-zeromem": "bin/dsh-zeromem.mjs"
|
|
11
|
+
},
|
|
9
12
|
"exports": {
|
|
10
13
|
".": "./lib/index.mjs",
|
|
11
14
|
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
12
15
|
"./package.json": "./package.json"
|
|
13
16
|
},
|
|
14
17
|
"files": [
|
|
18
|
+
"bin",
|
|
15
19
|
"lib",
|
|
16
20
|
"assets",
|
|
17
21
|
"cordis.patch.yml",
|
|
@@ -52,7 +56,7 @@
|
|
|
52
56
|
}
|
|
53
57
|
},
|
|
54
58
|
"scripts": {
|
|
55
|
-
"check": "node --check assets/panel.js",
|
|
56
|
-
"test": "node --test tests/contracts_and_llm.test.mjs tests/dsh_plugin.test.mjs tests/store_and_expiry.test.mjs"
|
|
59
|
+
"check": "node --check assets/panel.js && node --check bin/dsh-zeromem.mjs",
|
|
60
|
+
"test": "node --test tests/contracts_and_llm.test.mjs tests/dsh_plugin.test.mjs tests/store_and_expiry.test.mjs tests/timeline_and_portability.test.mjs"
|
|
57
61
|
}
|
|
58
62
|
}
|