@psiclawops/hypermem-memory 0.9.0 → 0.9.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/package.json +3 -3
- package/dist/index.d.ts +0 -24
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -350
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@psiclawops/hypermem-memory",
|
|
3
|
-
"version": "0.9.
|
|
4
|
-
"description": "HyperMem memory plugin for OpenClaw
|
|
3
|
+
"version": "0.9.1",
|
|
4
|
+
"description": "HyperMem memory plugin for OpenClaw \u2014 bridges HyperMem retrieval into the memory slot",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"typecheck": "tsc --noEmit"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@psiclawops/hypermem": "0.9.
|
|
41
|
+
"@psiclawops/hypermem": "0.9.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"openclaw": "*",
|
package/dist/index.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HyperMem Memory Plugin
|
|
3
|
-
*
|
|
4
|
-
* Thin adapter that bridges HyperMem's retrieval capabilities into
|
|
5
|
-
* OpenClaw's memory slot contract (`kind: "memory"`).
|
|
6
|
-
*
|
|
7
|
-
* The context engine plugin (hypercompositor) owns the full lifecycle:
|
|
8
|
-
* ingest, assemble, compact, afterTurn, bootstrap, dispose.
|
|
9
|
-
*
|
|
10
|
-
* This plugin owns the memory slot contract:
|
|
11
|
-
* - registerMemoryCapability() with runtime + publicArtifacts
|
|
12
|
-
* - memory_search tool backing via MemorySearchManager
|
|
13
|
-
* - Public artifacts for memory-wiki bridge
|
|
14
|
-
*
|
|
15
|
-
* Both plugins share the same HyperMem singleton (loaded from repo dist).
|
|
16
|
-
*/
|
|
17
|
-
declare const _default: {
|
|
18
|
-
id: string;
|
|
19
|
-
name: string;
|
|
20
|
-
description: string;
|
|
21
|
-
configSchema: import("openclaw/plugin-sdk").OpenClawPluginConfigSchema;
|
|
22
|
-
register: NonNullable<import("openclaw/plugin-sdk/plugin-entry").OpenClawPluginDefinition["register"]>;
|
|
23
|
-
} & Pick<import("openclaw/plugin-sdk/plugin-entry").OpenClawPluginDefinition, "kind" | "reload" | "nodeHostCommands" | "securityAuditCollectors">;
|
|
24
|
-
export default _default;
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;;;;;;;;AA0VH,wBAmBG"}
|
package/dist/index.js
DELETED
|
@@ -1,350 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HyperMem Memory Plugin
|
|
3
|
-
*
|
|
4
|
-
* Thin adapter that bridges HyperMem's retrieval capabilities into
|
|
5
|
-
* OpenClaw's memory slot contract (`kind: "memory"`).
|
|
6
|
-
*
|
|
7
|
-
* The context engine plugin (hypercompositor) owns the full lifecycle:
|
|
8
|
-
* ingest, assemble, compact, afterTurn, bootstrap, dispose.
|
|
9
|
-
*
|
|
10
|
-
* This plugin owns the memory slot contract:
|
|
11
|
-
* - registerMemoryCapability() with runtime + publicArtifacts
|
|
12
|
-
* - memory_search tool backing via MemorySearchManager
|
|
13
|
-
* - Public artifacts for memory-wiki bridge
|
|
14
|
-
*
|
|
15
|
-
* Both plugins share the same HyperMem singleton (loaded from repo dist).
|
|
16
|
-
*/
|
|
17
|
-
import { definePluginEntry, emptyPluginConfigSchema } from 'openclaw/plugin-sdk/plugin-entry';
|
|
18
|
-
import { matchTriggers, TRIGGER_REGISTRY } from '@psiclawops/hypermem';
|
|
19
|
-
import path from 'path';
|
|
20
|
-
import fs from 'fs/promises';
|
|
21
|
-
import os from 'os';
|
|
22
|
-
import { fileURLToPath } from 'url';
|
|
23
|
-
// ─── HyperMem singleton ────────────────────────────────────────
|
|
24
|
-
// Reuses the same singleton pattern as the context engine plugin.
|
|
25
|
-
// Both plugins load from the same installed runtime payload and share the instance.
|
|
26
|
-
const __pluginDir = path.dirname(fileURLToPath(import.meta.url));
|
|
27
|
-
async function resolveHyperMemPath() {
|
|
28
|
-
try {
|
|
29
|
-
const resolvedUrl = await import.meta.resolve('@psiclawops/hypermem');
|
|
30
|
-
return resolvedUrl.startsWith('file:') ? fileURLToPath(resolvedUrl) : resolvedUrl;
|
|
31
|
-
}
|
|
32
|
-
catch {
|
|
33
|
-
return path.resolve(__pluginDir, '../../dist/index.js');
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
let _hm = null;
|
|
37
|
-
let _hmInitPromise = null;
|
|
38
|
-
async function getHyperMem() {
|
|
39
|
-
if (_hm)
|
|
40
|
-
return _hm;
|
|
41
|
-
if (_hmInitPromise)
|
|
42
|
-
return _hmInitPromise;
|
|
43
|
-
_hmInitPromise = (async () => {
|
|
44
|
-
const hypermemPath = await resolveHyperMemPath();
|
|
45
|
-
const mod = await import(hypermemPath);
|
|
46
|
-
const HyperMem = mod.HyperMem;
|
|
47
|
-
const instance = await HyperMem.create({
|
|
48
|
-
dataDir: path.join(os.homedir(), '.openclaw/hypermem'),
|
|
49
|
-
cache: {
|
|
50
|
-
keyPrefix: 'hm:',
|
|
51
|
-
sessionTTL: 14400,
|
|
52
|
-
historyTTL: 86400,
|
|
53
|
-
},
|
|
54
|
-
});
|
|
55
|
-
_hm = instance;
|
|
56
|
-
return instance;
|
|
57
|
-
})();
|
|
58
|
-
return _hmInitPromise;
|
|
59
|
-
}
|
|
60
|
-
const DOCTRINE_COLLECTIONS = new Set([
|
|
61
|
-
'governance/policy',
|
|
62
|
-
'governance/charter',
|
|
63
|
-
'governance/comms',
|
|
64
|
-
'operations/agents',
|
|
65
|
-
]);
|
|
66
|
-
function doctrineScore(chunk, rank) {
|
|
67
|
-
const collectionBoost = chunk.collection.startsWith('governance/') ? 1.25 : 1.1;
|
|
68
|
-
return collectionBoost - Math.min(rank, 9) * 0.03;
|
|
69
|
-
}
|
|
70
|
-
function docChunkToMemoryResult(chunk, rank) {
|
|
71
|
-
return {
|
|
72
|
-
path: chunk.sourcePath,
|
|
73
|
-
startLine: 0,
|
|
74
|
-
endLine: 0,
|
|
75
|
-
score: doctrineScore(chunk, rank),
|
|
76
|
-
snippet: chunk.content.slice(0, 500),
|
|
77
|
-
source: 'memory',
|
|
78
|
-
citation: `[doc:${chunk.collection}:${chunk.sectionPath}]`,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Create a MemorySearchManager backed by HyperMem's retrieval pipeline.
|
|
83
|
-
*
|
|
84
|
-
* Uses HyperMem's:
|
|
85
|
-
* - library.db fact search (FTS5 + BM25)
|
|
86
|
-
* - vector store semantic search (when available)
|
|
87
|
-
* - message search (full-text across conversations)
|
|
88
|
-
*/
|
|
89
|
-
function createMemorySearchManager(hm, agentId, workspaceDir) {
|
|
90
|
-
return {
|
|
91
|
-
async search(query, opts) {
|
|
92
|
-
const maxResults = opts?.maxResults ?? 10;
|
|
93
|
-
const minScore = opts?.minScore ?? 0;
|
|
94
|
-
const results = [];
|
|
95
|
-
const seenDocChunks = new Set();
|
|
96
|
-
// 0. Canonical doctrine search. Explicit governance queries should surface
|
|
97
|
-
// policy, charter, comms, and AGENTS chunks before stale daily-memory folklore.
|
|
98
|
-
try {
|
|
99
|
-
const triggers = matchTriggers(query, TRIGGER_REGISTRY)
|
|
100
|
-
.filter(trigger => DOCTRINE_COLLECTIONS.has(trigger.collection))
|
|
101
|
-
.slice(0, 4);
|
|
102
|
-
for (const trigger of triggers) {
|
|
103
|
-
const chunks = hm.queryDocChunks({
|
|
104
|
-
collection: trigger.collection,
|
|
105
|
-
agentId,
|
|
106
|
-
keyword: query,
|
|
107
|
-
limit: Math.max(3, Math.ceil(maxResults / Math.max(1, triggers.length))),
|
|
108
|
-
});
|
|
109
|
-
chunks.forEach((chunk, rank) => {
|
|
110
|
-
const key = `${chunk.sourcePath}:${chunk.sectionPath}:${chunk.sourceHash}`;
|
|
111
|
-
if (seenDocChunks.has(key))
|
|
112
|
-
return;
|
|
113
|
-
seenDocChunks.add(key);
|
|
114
|
-
const result = docChunkToMemoryResult(chunk, rank);
|
|
115
|
-
if (result.score >= minScore)
|
|
116
|
-
results.push(result);
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
catch {
|
|
121
|
-
// Doctrine search is a precision boost, not a hard dependency.
|
|
122
|
-
}
|
|
123
|
-
// 1. Fact search (FTS5 + BM25 from library.db)
|
|
124
|
-
try {
|
|
125
|
-
const facts = hm.getActiveFacts(agentId, { limit: maxResults * 2 });
|
|
126
|
-
// Simple keyword matching for facts (FTS5 handles this in the DB layer)
|
|
127
|
-
const queryLower = query.toLowerCase();
|
|
128
|
-
const queryTerms = queryLower.split(/\s+/).filter(t => t.length > 2);
|
|
129
|
-
for (const fact of facts) {
|
|
130
|
-
const contentLower = fact.content.toLowerCase();
|
|
131
|
-
const matchCount = queryTerms.filter(t => contentLower.includes(t)).length;
|
|
132
|
-
if (matchCount === 0)
|
|
133
|
-
continue;
|
|
134
|
-
const score = matchCount / queryTerms.length;
|
|
135
|
-
if (score < minScore)
|
|
136
|
-
continue;
|
|
137
|
-
results.push({
|
|
138
|
-
path: `library://facts/${fact.id}`,
|
|
139
|
-
startLine: 0,
|
|
140
|
-
endLine: 0,
|
|
141
|
-
score,
|
|
142
|
-
snippet: fact.content.slice(0, 300),
|
|
143
|
-
source: 'memory',
|
|
144
|
-
citation: fact.domain ? `[fact:${fact.domain}]` : '[fact]',
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
catch {
|
|
149
|
-
// Fact search non-fatal
|
|
150
|
-
}
|
|
151
|
-
// 2. Vector/semantic search (when available)
|
|
152
|
-
try {
|
|
153
|
-
const vectorStore = hm.getVectorStore();
|
|
154
|
-
if (vectorStore) {
|
|
155
|
-
const vectorResults = await hm.semanticSearch(agentId, query, {
|
|
156
|
-
limit: maxResults,
|
|
157
|
-
maxDistance: 1.5,
|
|
158
|
-
});
|
|
159
|
-
for (const vr of vectorResults) {
|
|
160
|
-
const score = 1.0 - (vr.distance / 2.0); // normalize distance to 0-1 score
|
|
161
|
-
if (score < minScore)
|
|
162
|
-
continue;
|
|
163
|
-
results.push({
|
|
164
|
-
path: `vector://${vr.sourceTable}/${vr.sourceId}`,
|
|
165
|
-
startLine: 0,
|
|
166
|
-
endLine: 0,
|
|
167
|
-
score,
|
|
168
|
-
snippet: vr.content.slice(0, 300),
|
|
169
|
-
source: 'memory',
|
|
170
|
-
citation: `[${vr.sourceTable}:${vr.sourceId}]`,
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
catch {
|
|
176
|
-
// Vector search non-fatal
|
|
177
|
-
}
|
|
178
|
-
// 3. Message search (FTS5 across conversations)
|
|
179
|
-
try {
|
|
180
|
-
const messageResults = hm.search(agentId, query, maxResults);
|
|
181
|
-
for (const msg of messageResults) {
|
|
182
|
-
const content = msg.textContent ?? '';
|
|
183
|
-
results.push({
|
|
184
|
-
path: `messages://${msg.conversationId ?? 'unknown'}/${msg.id}`,
|
|
185
|
-
startLine: 0,
|
|
186
|
-
endLine: 0,
|
|
187
|
-
score: 0.5, // message search doesn't return scores, use mid-range
|
|
188
|
-
snippet: content.slice(0, 300),
|
|
189
|
-
source: 'sessions',
|
|
190
|
-
citation: `[message:${msg.id}]`,
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
catch {
|
|
195
|
-
// Message search non-fatal
|
|
196
|
-
}
|
|
197
|
-
// Deduplicate by content similarity, sort by score, limit
|
|
198
|
-
results.sort((a, b) => b.score - a.score);
|
|
199
|
-
return results.slice(0, maxResults);
|
|
200
|
-
},
|
|
201
|
-
async readFile(params) {
|
|
202
|
-
const absPath = path.resolve(workspaceDir, params.relPath);
|
|
203
|
-
try {
|
|
204
|
-
const content = await fs.readFile(absPath, 'utf-8');
|
|
205
|
-
const lines = content.split('\n');
|
|
206
|
-
const from = params.from ?? 0;
|
|
207
|
-
const count = params.lines ?? lines.length;
|
|
208
|
-
const slice = lines.slice(from, from + count);
|
|
209
|
-
return { text: slice.join('\n'), path: absPath };
|
|
210
|
-
}
|
|
211
|
-
catch (err) {
|
|
212
|
-
return { text: `Error reading ${absPath}: ${err.message}`, path: absPath };
|
|
213
|
-
}
|
|
214
|
-
},
|
|
215
|
-
status() {
|
|
216
|
-
const vectorStore = hm.getVectorStore();
|
|
217
|
-
const vectorStats = vectorStore ? hm.getVectorStats(agentId) : null;
|
|
218
|
-
return {
|
|
219
|
-
backend: 'builtin',
|
|
220
|
-
provider: 'hypermem',
|
|
221
|
-
model: 'hypermem-fts5+vector',
|
|
222
|
-
workspaceDir,
|
|
223
|
-
dbPath: path.join(os.homedir(), '.openclaw/hypermem'),
|
|
224
|
-
sources: ['memory', 'sessions'],
|
|
225
|
-
fts: {
|
|
226
|
-
enabled: true,
|
|
227
|
-
available: true,
|
|
228
|
-
},
|
|
229
|
-
vector: {
|
|
230
|
-
enabled: !!vectorStore,
|
|
231
|
-
available: !!vectorStore,
|
|
232
|
-
dims: vectorStats?.dimensions
|
|
233
|
-
?? vectorStats?.dims
|
|
234
|
-
?? undefined,
|
|
235
|
-
},
|
|
236
|
-
custom: {
|
|
237
|
-
vectorStats: vectorStats ?? undefined,
|
|
238
|
-
factCount: hm.getActiveFacts(agentId, { limit: 1 }).length > 0 ? 'available' : 'empty',
|
|
239
|
-
},
|
|
240
|
-
};
|
|
241
|
-
},
|
|
242
|
-
async probeEmbeddingAvailability() {
|
|
243
|
-
try {
|
|
244
|
-
const vectorStore = hm.getVectorStore();
|
|
245
|
-
if (!vectorStore)
|
|
246
|
-
return { ok: false, error: 'Vector store not initialized' };
|
|
247
|
-
return { ok: true };
|
|
248
|
-
}
|
|
249
|
-
catch (err) {
|
|
250
|
-
return { ok: false, error: err.message };
|
|
251
|
-
}
|
|
252
|
-
},
|
|
253
|
-
async probeVectorAvailability() {
|
|
254
|
-
return !!hm.getVectorStore();
|
|
255
|
-
},
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
// ─── Manager cache ──────────────────────────────────────────────
|
|
259
|
-
// One manager per agentId; closed on plugin dispose.
|
|
260
|
-
const _managers = new Map();
|
|
261
|
-
// ─── Plugin Entry ───────────────────────────────────────────────
|
|
262
|
-
export default definePluginEntry({
|
|
263
|
-
id: 'hypermem',
|
|
264
|
-
name: 'HyperMem Memory',
|
|
265
|
-
description: 'Bridges HyperMem retrieval (facts, vectors, messages) into the OpenClaw memory slot for memory_search and memory-wiki.',
|
|
266
|
-
kind: 'memory',
|
|
267
|
-
configSchema: emptyPluginConfigSchema(),
|
|
268
|
-
register(api) {
|
|
269
|
-
api.registerMemoryCapability({
|
|
270
|
-
runtime: {
|
|
271
|
-
async getMemorySearchManager(params) {
|
|
272
|
-
try {
|
|
273
|
-
const hm = await getHyperMem();
|
|
274
|
-
const agentId = params.agentId || 'main';
|
|
275
|
-
// Cache managers per agent
|
|
276
|
-
if (!_managers.has(agentId)) {
|
|
277
|
-
// Resolve workspace dir from agent config
|
|
278
|
-
const agents = params.cfg?.agents?.list ?? [];
|
|
279
|
-
const agentCfg = agents.find((a) => a.id === agentId);
|
|
280
|
-
const workspaceDir = agentCfg?.workspace
|
|
281
|
-
?? path.join(os.homedir(), '.openclaw/workspace');
|
|
282
|
-
_managers.set(agentId, createMemorySearchManager(hm, agentId, workspaceDir));
|
|
283
|
-
}
|
|
284
|
-
return { manager: _managers.get(agentId) };
|
|
285
|
-
}
|
|
286
|
-
catch (err) {
|
|
287
|
-
return { manager: null, error: err.message };
|
|
288
|
-
}
|
|
289
|
-
},
|
|
290
|
-
resolveMemoryBackendConfig(_params) {
|
|
291
|
-
return { backend: 'builtin' };
|
|
292
|
-
},
|
|
293
|
-
async closeAllMemorySearchManagers() {
|
|
294
|
-
_managers.clear();
|
|
295
|
-
},
|
|
296
|
-
},
|
|
297
|
-
publicArtifacts: {
|
|
298
|
-
async listArtifacts(params) {
|
|
299
|
-
const artifacts = [];
|
|
300
|
-
// List memory files for each agent
|
|
301
|
-
const agents = params.cfg?.agents?.list ?? [];
|
|
302
|
-
for (const agent of agents) {
|
|
303
|
-
const agentId = agent.id;
|
|
304
|
-
if (!agentId)
|
|
305
|
-
continue;
|
|
306
|
-
const workspace = agent.workspace;
|
|
307
|
-
if (!workspace)
|
|
308
|
-
continue;
|
|
309
|
-
const memoryDir = path.join(workspace, 'memory');
|
|
310
|
-
try {
|
|
311
|
-
const files = await fs.readdir(memoryDir);
|
|
312
|
-
for (const file of files) {
|
|
313
|
-
if (!file.endsWith('.md'))
|
|
314
|
-
continue;
|
|
315
|
-
artifacts.push({
|
|
316
|
-
kind: 'memory-daily',
|
|
317
|
-
workspaceDir: workspace,
|
|
318
|
-
relativePath: `memory/${file}`,
|
|
319
|
-
absolutePath: path.join(memoryDir, file),
|
|
320
|
-
agentIds: [agentId],
|
|
321
|
-
contentType: 'markdown',
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
catch {
|
|
326
|
-
// No memory dir for this agent — skip
|
|
327
|
-
}
|
|
328
|
-
// Also expose MEMORY.md index
|
|
329
|
-
const memoryIndex = path.join(workspace, 'MEMORY.md');
|
|
330
|
-
try {
|
|
331
|
-
await fs.access(memoryIndex);
|
|
332
|
-
artifacts.push({
|
|
333
|
-
kind: 'memory-index',
|
|
334
|
-
workspaceDir: workspace,
|
|
335
|
-
relativePath: 'MEMORY.md',
|
|
336
|
-
absolutePath: memoryIndex,
|
|
337
|
-
agentIds: [agentId],
|
|
338
|
-
contentType: 'markdown',
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
catch {
|
|
342
|
-
// No MEMORY.md — skip
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
return artifacts;
|
|
346
|
-
},
|
|
347
|
-
},
|
|
348
|
-
});
|
|
349
|
-
},
|
|
350
|
-
});
|