@imliulian/dsh-zeromem 0.0.0-stage → 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 +23 -0
- package/LICENSE +661 -0
- package/NOTICE +34 -0
- package/README.md +137 -2
- package/README.zh.md +139 -0
- package/assets/panel.js +2986 -0
- package/bin/dsh-zeromem.mjs +187 -0
- package/cordis.patch.yml +13 -0
- package/lib/config.mjs +469 -0
- package/lib/contracts.mjs +483 -0
- package/lib/expiry.mjs +359 -0
- package/lib/hooks.mjs +284 -0
- package/lib/index.mjs +120 -0
- package/lib/llm.mjs +827 -0
- package/lib/memory.mjs +824 -0
- package/lib/portability.mjs +819 -0
- package/lib/store.mjs +1248 -0
- package/lib/tools.mjs +527 -0
- package/lib/web.mjs +629 -0
- package/package.json +60 -4
package/lib/index.mjs
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @imliulian/dsh-zeromem — DeepSeek Harness Cordis plugin entry.
|
|
3
|
+
*
|
|
4
|
+
* Zero runtime third-party dependencies (Node built-in `node:sqlite` + FTS5 + HTTP/fetch).
|
|
5
|
+
* Works across DSH Web, Official DSH Desktop (Electron), and Headless profiles.
|
|
6
|
+
*
|
|
7
|
+
* Boot safety invariant:
|
|
8
|
+
* DSH startup is all-or-nothing. Every service attachment here is isolated and 100% fail-open
|
|
9
|
+
* so missing services, offline Ollama, or bad config never prevent DSH from booting.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { attachZeroMemHooks } from "./hooks.mjs";
|
|
13
|
+
import { ZeroMemEngine } from "./memory.mjs";
|
|
14
|
+
import { backupDatabase, exportMarkdown } from "./portability.mjs";
|
|
15
|
+
import { SQLiteMemoryStore } from "./store.mjs";
|
|
16
|
+
import { registerZeroMemTools } from "./tools.mjs";
|
|
17
|
+
import { mountWebServer, registerDesktopIndexInject } from "./web.mjs";
|
|
18
|
+
|
|
19
|
+
export const name = "zeromem";
|
|
20
|
+
|
|
21
|
+
export function apply(root, config = {}) {
|
|
22
|
+
const disposers = [];
|
|
23
|
+
|
|
24
|
+
// 1. Register Desktop Electron index-inject line synchronously BEFORE any root.inject()
|
|
25
|
+
// so official Desktop collects it during one-shot startup injection.
|
|
26
|
+
try {
|
|
27
|
+
disposers.push(registerDesktopIndexInject(root));
|
|
28
|
+
} catch (err) {
|
|
29
|
+
console.warn("[dsh-zeromem] desktop index-inject skipped:", err?.message || err);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let engine;
|
|
33
|
+
try {
|
|
34
|
+
engine = new ZeroMemEngine({
|
|
35
|
+
configOptions: {
|
|
36
|
+
initialOverrides: config && typeof config === "object" ? config : null,
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
} catch (err) {
|
|
40
|
+
console.warn("[dsh-zeromem] failed to initialize engine (degraded):", err?.message || err);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// 2. Native agent lifecycle hooks (pre-step recall + turn-stopping background remember)
|
|
45
|
+
try {
|
|
46
|
+
if (typeof root?.inject === "function") {
|
|
47
|
+
root.inject(["agents"], (agentCtx) => {
|
|
48
|
+
try {
|
|
49
|
+
const dispose = attachZeroMemHooks(agentCtx, engine);
|
|
50
|
+
if (typeof agentCtx?.effect === "function") {
|
|
51
|
+
agentCtx.effect(() => dispose, "zeromem: agent hooks");
|
|
52
|
+
} else {
|
|
53
|
+
disposers.push(dispose);
|
|
54
|
+
}
|
|
55
|
+
} catch (err) {
|
|
56
|
+
console.warn("[dsh-zeromem] agent hooks skipped:", err?.message || err);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
} catch (err) {
|
|
61
|
+
console.warn("[dsh-zeromem] agents inject failed:", err?.message || err);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// 3. Native DSH tools (zeromem_recall / remember / stats / evict / restore)
|
|
65
|
+
try {
|
|
66
|
+
if (typeof root?.inject === "function") {
|
|
67
|
+
root.inject(["tools"], (toolCtx) => {
|
|
68
|
+
try {
|
|
69
|
+
const dispose = registerZeroMemTools(toolCtx, engine);
|
|
70
|
+
if (typeof toolCtx?.effect === "function") {
|
|
71
|
+
toolCtx.effect(() => dispose, "zeromem: tools");
|
|
72
|
+
} else {
|
|
73
|
+
disposers.push(dispose);
|
|
74
|
+
}
|
|
75
|
+
} catch (err) {
|
|
76
|
+
console.warn("[dsh-zeromem] tools registration skipped:", err?.message || err);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
} catch (err) {
|
|
81
|
+
console.warn("[dsh-zeromem] tools inject failed:", err?.message || err);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 4. Embedded Web Workbench & HTTP API (auto-skipped in headless profiles without webServer)
|
|
85
|
+
try {
|
|
86
|
+
if (typeof root?.inject === "function") {
|
|
87
|
+
root.inject(["webServer"], (webCtx) => {
|
|
88
|
+
try {
|
|
89
|
+
const dispose = mountWebServer(webCtx, engine);
|
|
90
|
+
if (typeof webCtx?.effect === "function") {
|
|
91
|
+
webCtx.effect(() => dispose, "zeromem: web workbench");
|
|
92
|
+
} else {
|
|
93
|
+
disposers.push(dispose);
|
|
94
|
+
}
|
|
95
|
+
} catch (err) {
|
|
96
|
+
console.warn("[dsh-zeromem] web workbench skipped:", err?.message || err);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
} catch (err) {
|
|
101
|
+
console.warn("[dsh-zeromem] webServer inject failed:", err?.message || err);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (typeof root?.effect === "function") {
|
|
105
|
+
root.effect(() => () => {
|
|
106
|
+
for (const d of disposers) {
|
|
107
|
+
if (typeof d === "function") {
|
|
108
|
+
try {
|
|
109
|
+
d();
|
|
110
|
+
} catch {
|
|
111
|
+
// ignore
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}, "zeromem: root cleanup");
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export default { name, apply };
|
|
120
|
+
export { ZeroMemEngine, SQLiteMemoryStore, exportMarkdown, backupDatabase };
|