@xdarkicex/openclaw-memory-libravdb 1.4.44 → 1.4.45
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/cli.js +15 -4
- package/dist/identity.d.ts +3 -0
- package/dist/identity.js +3 -0
- package/dist/index.js +113 -103
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2,6 +2,7 @@ import { createInterface } from "node:readline/promises";
|
|
|
2
2
|
import { stdin, stdout } from "node:process";
|
|
3
3
|
import { MEMORY_CLI_DESCRIPTOR, isMemorySlotSelected } from "./cli-descriptors.js";
|
|
4
4
|
import { resolveDurableNamespace } from "./memory-scopes.js";
|
|
5
|
+
import { resolveIdentity } from "./identity.js";
|
|
5
6
|
import { promoteDreamDiaryFile } from "./dream-promotion.js";
|
|
6
7
|
import { buildMemoryRuntimeBridge } from "./memory-runtime.js";
|
|
7
8
|
export function registerMemoryCli(api, runtime, cfg, logger = console) {
|
|
@@ -143,7 +144,7 @@ async function runStatus(runtime, cfg, logger, opts = {}) {
|
|
|
143
144
|
try {
|
|
144
145
|
const rpc = await runtime.getRpc();
|
|
145
146
|
const status = await rpc.call("status", {});
|
|
146
|
-
const deep = opts.deep ? await runDeepStatusProbe(rpc) : undefined;
|
|
147
|
+
const deep = opts.deep ? await runDeepStatusProbe(rpc, cfg) : undefined;
|
|
147
148
|
if (opts.json) {
|
|
148
149
|
console.log(JSON.stringify({ status, ...(deep ? { deep } : {}) }, null, 2));
|
|
149
150
|
if (deep && !deep.ok) {
|
|
@@ -192,10 +193,20 @@ async function runStatus(runtime, cfg, logger, opts = {}) {
|
|
|
192
193
|
process.exitCode = 1;
|
|
193
194
|
}
|
|
194
195
|
}
|
|
195
|
-
const
|
|
196
|
-
async function runDeepStatusProbe(rpc) {
|
|
196
|
+
const AUTHORED_STATUS_COLLECTIONS = ["authored:hard", "authored:soft", "authored:variant"];
|
|
197
|
+
async function runDeepStatusProbe(rpc, cfg) {
|
|
198
|
+
// Resolve userId without triggering auto-derive file writes.
|
|
199
|
+
// status --deep should be read-only; if no userId is configured and no
|
|
200
|
+
// identity file exists, fall back to "default" rather than creating one.
|
|
201
|
+
const { userId } = resolveIdentity({
|
|
202
|
+
configUserId: cfg.userId,
|
|
203
|
+
identityPath: cfg.identityPath,
|
|
204
|
+
noAutoPersist: true,
|
|
205
|
+
});
|
|
206
|
+
const durableCollections = [`user:${userId}`, "global"];
|
|
207
|
+
const allCollections = [...AUTHORED_STATUS_COLLECTIONS, ...durableCollections];
|
|
197
208
|
const probes = [];
|
|
198
|
-
for (const collection of
|
|
209
|
+
for (const collection of allCollections) {
|
|
199
210
|
try {
|
|
200
211
|
const result = await rpc.call("search_text", {
|
|
201
212
|
collection,
|
package/dist/identity.d.ts
CHANGED
|
@@ -9,4 +9,7 @@ export declare function resolveIdentity(params: {
|
|
|
9
9
|
identityPath?: string;
|
|
10
10
|
sessionKey?: string;
|
|
11
11
|
logger?: LoggerLike;
|
|
12
|
+
/** When true, skip writing the auto-derived identity file. Useful for
|
|
13
|
+
* read-only commands (e.g. status --deep) that should not mutate disk. */
|
|
14
|
+
noAutoPersist?: boolean;
|
|
12
15
|
}): ResolvedIdentity;
|
package/dist/identity.js
CHANGED
|
@@ -96,6 +96,9 @@ export function resolveIdentity(params) {
|
|
|
96
96
|
return { userId: "default", source: "default" };
|
|
97
97
|
}
|
|
98
98
|
const autoId = deriveAutoId(parts);
|
|
99
|
+
if (params.noAutoPersist) {
|
|
100
|
+
return { userId: autoId, source: "auto" };
|
|
101
|
+
}
|
|
99
102
|
try {
|
|
100
103
|
writeIdentityFile(filePath, autoId, parts);
|
|
101
104
|
params.logger?.info?.(`LibraVDB: auto-derived identity "${autoId}" written to ${filePath}`);
|
package/dist/index.js
CHANGED
|
@@ -32179,6 +32179,108 @@ function firstNonEmpty(value) {
|
|
|
32179
32179
|
return trimmed.length > 0 ? trimmed : void 0;
|
|
32180
32180
|
}
|
|
32181
32181
|
|
|
32182
|
+
// src/identity.ts
|
|
32183
|
+
import { userInfo, hostname } from "node:os";
|
|
32184
|
+
import { createHash } from "node:crypto";
|
|
32185
|
+
import {
|
|
32186
|
+
existsSync,
|
|
32187
|
+
readFileSync,
|
|
32188
|
+
writeFileSync,
|
|
32189
|
+
renameSync,
|
|
32190
|
+
mkdirSync
|
|
32191
|
+
} from "node:fs";
|
|
32192
|
+
import { join, dirname } from "node:path";
|
|
32193
|
+
function resolveIdentityPath(configuredPath) {
|
|
32194
|
+
if (configuredPath) return configuredPath;
|
|
32195
|
+
const stateDir = process.env.OPENCLAW_STATE_DIR?.trim();
|
|
32196
|
+
if (stateDir) return join(stateDir, "libravdb-identity.json");
|
|
32197
|
+
const home = userInfo().homedir;
|
|
32198
|
+
return join(home, ".openclaw", "libravdb-identity.json");
|
|
32199
|
+
}
|
|
32200
|
+
function deriveIdentityParts() {
|
|
32201
|
+
let username;
|
|
32202
|
+
let home;
|
|
32203
|
+
try {
|
|
32204
|
+
const info = userInfo();
|
|
32205
|
+
username = info.username;
|
|
32206
|
+
home = info.homedir;
|
|
32207
|
+
} catch {
|
|
32208
|
+
username = process.env.USER || process.env.USERNAME || process.env.LOGNAME || "anon";
|
|
32209
|
+
home = process.env.HOME || process.env.USERPROFILE || "unknown";
|
|
32210
|
+
}
|
|
32211
|
+
const host = hostname();
|
|
32212
|
+
const homeHash = createHash("sha256").update(home.replace(/\\/g, "/").toLowerCase()).digest("hex").slice(0, 8);
|
|
32213
|
+
return { username, host, home, homeHash };
|
|
32214
|
+
}
|
|
32215
|
+
function deriveAutoId(parts) {
|
|
32216
|
+
return `${parts.username}@${parts.host}#${parts.homeHash}`;
|
|
32217
|
+
}
|
|
32218
|
+
function writeIdentityFile(path5, userId, parts) {
|
|
32219
|
+
const identity = {
|
|
32220
|
+
userId,
|
|
32221
|
+
derivedFrom: {
|
|
32222
|
+
username: parts.username,
|
|
32223
|
+
hostname: parts.host,
|
|
32224
|
+
homeHash: parts.homeHash,
|
|
32225
|
+
platform: process.platform
|
|
32226
|
+
},
|
|
32227
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
32228
|
+
};
|
|
32229
|
+
const dir = dirname(path5);
|
|
32230
|
+
mkdirSync(dir, { recursive: true });
|
|
32231
|
+
const tmp = `${path5}.${process.pid}.${Math.random().toString(36).slice(2, 8)}.tmp`;
|
|
32232
|
+
writeFileSync(tmp, JSON.stringify(identity, null, 2) + "\n");
|
|
32233
|
+
renameSync(tmp, path5);
|
|
32234
|
+
}
|
|
32235
|
+
function resolveIdentity(params) {
|
|
32236
|
+
const configUserId = params.configUserId?.trim();
|
|
32237
|
+
if (configUserId) {
|
|
32238
|
+
return { userId: configUserId, source: "config" };
|
|
32239
|
+
}
|
|
32240
|
+
const filePath = resolveIdentityPath(params.identityPath);
|
|
32241
|
+
if (existsSync(filePath)) {
|
|
32242
|
+
try {
|
|
32243
|
+
const raw = readFileSync(filePath, "utf8");
|
|
32244
|
+
const parsed = JSON.parse(raw);
|
|
32245
|
+
if (parsed.userId && typeof parsed.userId === "string") {
|
|
32246
|
+
const trimmed = parsed.userId.trim();
|
|
32247
|
+
if (trimmed.length > 0) {
|
|
32248
|
+
return { userId: trimmed, source: "file" };
|
|
32249
|
+
}
|
|
32250
|
+
}
|
|
32251
|
+
} catch (error) {
|
|
32252
|
+
params.logger?.warn?.(
|
|
32253
|
+
`LibraVDB: failed to read identity file at ${filePath}: ${error instanceof Error ? error.message : String(error)}`
|
|
32254
|
+
);
|
|
32255
|
+
}
|
|
32256
|
+
}
|
|
32257
|
+
let parts;
|
|
32258
|
+
try {
|
|
32259
|
+
parts = deriveIdentityParts();
|
|
32260
|
+
} catch {
|
|
32261
|
+
const fallback = params.sessionKey?.trim();
|
|
32262
|
+
if (fallback) {
|
|
32263
|
+
return { userId: `session-key:${fallback}`, source: "session-key" };
|
|
32264
|
+
}
|
|
32265
|
+
return { userId: "default", source: "default" };
|
|
32266
|
+
}
|
|
32267
|
+
const autoId = deriveAutoId(parts);
|
|
32268
|
+
if (params.noAutoPersist) {
|
|
32269
|
+
return { userId: autoId, source: "auto" };
|
|
32270
|
+
}
|
|
32271
|
+
try {
|
|
32272
|
+
writeIdentityFile(filePath, autoId, parts);
|
|
32273
|
+
params.logger?.info?.(
|
|
32274
|
+
`LibraVDB: auto-derived identity "${autoId}" written to ${filePath}`
|
|
32275
|
+
);
|
|
32276
|
+
} catch (error) {
|
|
32277
|
+
params.logger?.warn?.(
|
|
32278
|
+
`LibraVDB: failed to persist identity file at ${filePath}: ${error instanceof Error ? error.message : String(error)}`
|
|
32279
|
+
);
|
|
32280
|
+
}
|
|
32281
|
+
return { userId: autoId, source: "auto" };
|
|
32282
|
+
}
|
|
32283
|
+
|
|
32182
32284
|
// src/dream-promotion.ts
|
|
32183
32285
|
import fs from "node:fs";
|
|
32184
32286
|
import fsp from "node:fs/promises";
|
|
@@ -32748,105 +32850,6 @@ function formatError(error) {
|
|
|
32748
32850
|
}
|
|
32749
32851
|
var textDecoder = new TextDecoder();
|
|
32750
32852
|
|
|
32751
|
-
// src/identity.ts
|
|
32752
|
-
import { userInfo, hostname } from "node:os";
|
|
32753
|
-
import { createHash } from "node:crypto";
|
|
32754
|
-
import {
|
|
32755
|
-
existsSync,
|
|
32756
|
-
readFileSync,
|
|
32757
|
-
writeFileSync,
|
|
32758
|
-
renameSync,
|
|
32759
|
-
mkdirSync
|
|
32760
|
-
} from "node:fs";
|
|
32761
|
-
import { join, dirname } from "node:path";
|
|
32762
|
-
function resolveIdentityPath(configuredPath) {
|
|
32763
|
-
if (configuredPath) return configuredPath;
|
|
32764
|
-
const stateDir = process.env.OPENCLAW_STATE_DIR?.trim();
|
|
32765
|
-
if (stateDir) return join(stateDir, "libravdb-identity.json");
|
|
32766
|
-
const home = userInfo().homedir;
|
|
32767
|
-
return join(home, ".openclaw", "libravdb-identity.json");
|
|
32768
|
-
}
|
|
32769
|
-
function deriveIdentityParts() {
|
|
32770
|
-
let username;
|
|
32771
|
-
let home;
|
|
32772
|
-
try {
|
|
32773
|
-
const info = userInfo();
|
|
32774
|
-
username = info.username;
|
|
32775
|
-
home = info.homedir;
|
|
32776
|
-
} catch {
|
|
32777
|
-
username = process.env.USER || process.env.USERNAME || process.env.LOGNAME || "anon";
|
|
32778
|
-
home = process.env.HOME || process.env.USERPROFILE || "unknown";
|
|
32779
|
-
}
|
|
32780
|
-
const host = hostname();
|
|
32781
|
-
const homeHash = createHash("sha256").update(home.replace(/\\/g, "/").toLowerCase()).digest("hex").slice(0, 8);
|
|
32782
|
-
return { username, host, home, homeHash };
|
|
32783
|
-
}
|
|
32784
|
-
function deriveAutoId(parts) {
|
|
32785
|
-
return `${parts.username}@${parts.host}#${parts.homeHash}`;
|
|
32786
|
-
}
|
|
32787
|
-
function writeIdentityFile(path5, userId, parts) {
|
|
32788
|
-
const identity = {
|
|
32789
|
-
userId,
|
|
32790
|
-
derivedFrom: {
|
|
32791
|
-
username: parts.username,
|
|
32792
|
-
hostname: parts.host,
|
|
32793
|
-
homeHash: parts.homeHash,
|
|
32794
|
-
platform: process.platform
|
|
32795
|
-
},
|
|
32796
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
32797
|
-
};
|
|
32798
|
-
const dir = dirname(path5);
|
|
32799
|
-
mkdirSync(dir, { recursive: true });
|
|
32800
|
-
const tmp = `${path5}.${process.pid}.${Math.random().toString(36).slice(2, 8)}.tmp`;
|
|
32801
|
-
writeFileSync(tmp, JSON.stringify(identity, null, 2) + "\n");
|
|
32802
|
-
renameSync(tmp, path5);
|
|
32803
|
-
}
|
|
32804
|
-
function resolveIdentity(params) {
|
|
32805
|
-
const configUserId = params.configUserId?.trim();
|
|
32806
|
-
if (configUserId) {
|
|
32807
|
-
return { userId: configUserId, source: "config" };
|
|
32808
|
-
}
|
|
32809
|
-
const filePath = resolveIdentityPath(params.identityPath);
|
|
32810
|
-
if (existsSync(filePath)) {
|
|
32811
|
-
try {
|
|
32812
|
-
const raw = readFileSync(filePath, "utf8");
|
|
32813
|
-
const parsed = JSON.parse(raw);
|
|
32814
|
-
if (parsed.userId && typeof parsed.userId === "string") {
|
|
32815
|
-
const trimmed = parsed.userId.trim();
|
|
32816
|
-
if (trimmed.length > 0) {
|
|
32817
|
-
return { userId: trimmed, source: "file" };
|
|
32818
|
-
}
|
|
32819
|
-
}
|
|
32820
|
-
} catch (error) {
|
|
32821
|
-
params.logger?.warn?.(
|
|
32822
|
-
`LibraVDB: failed to read identity file at ${filePath}: ${error instanceof Error ? error.message : String(error)}`
|
|
32823
|
-
);
|
|
32824
|
-
}
|
|
32825
|
-
}
|
|
32826
|
-
let parts;
|
|
32827
|
-
try {
|
|
32828
|
-
parts = deriveIdentityParts();
|
|
32829
|
-
} catch {
|
|
32830
|
-
const fallback = params.sessionKey?.trim();
|
|
32831
|
-
if (fallback) {
|
|
32832
|
-
return { userId: `session-key:${fallback}`, source: "session-key" };
|
|
32833
|
-
}
|
|
32834
|
-
return { userId: "default", source: "default" };
|
|
32835
|
-
}
|
|
32836
|
-
const autoId = deriveAutoId(parts);
|
|
32837
|
-
try {
|
|
32838
|
-
writeIdentityFile(filePath, autoId, parts);
|
|
32839
|
-
params.logger?.info?.(
|
|
32840
|
-
`LibraVDB: auto-derived identity "${autoId}" written to ${filePath}`
|
|
32841
|
-
);
|
|
32842
|
-
} catch (error) {
|
|
32843
|
-
params.logger?.warn?.(
|
|
32844
|
-
`LibraVDB: failed to persist identity file at ${filePath}: ${error instanceof Error ? error.message : String(error)}`
|
|
32845
|
-
);
|
|
32846
|
-
}
|
|
32847
|
-
return { userId: autoId, source: "auto" };
|
|
32848
|
-
}
|
|
32849
|
-
|
|
32850
32853
|
// src/dream-routing.ts
|
|
32851
32854
|
var DREAM_COLLECTION_PREFIX = "dream:";
|
|
32852
32855
|
var DREAM_PATTERN_RULES = [
|
|
@@ -33242,7 +33245,7 @@ async function runStatus(runtime, cfg, logger, opts = {}) {
|
|
|
33242
33245
|
try {
|
|
33243
33246
|
const rpc = await runtime.getRpc();
|
|
33244
33247
|
const status = await rpc.call("status", {});
|
|
33245
|
-
const deep = opts.deep ? await runDeepStatusProbe(rpc) : void 0;
|
|
33248
|
+
const deep = opts.deep ? await runDeepStatusProbe(rpc, cfg) : void 0;
|
|
33246
33249
|
if (opts.json) {
|
|
33247
33250
|
console.log(JSON.stringify({ status, ...deep ? { deep } : {} }, null, 2));
|
|
33248
33251
|
if (deep && !deep.ok) {
|
|
@@ -33296,10 +33299,17 @@ async function runStatus(runtime, cfg, logger, opts = {}) {
|
|
|
33296
33299
|
process.exitCode = 1;
|
|
33297
33300
|
}
|
|
33298
33301
|
}
|
|
33299
|
-
var
|
|
33300
|
-
async function runDeepStatusProbe(rpc) {
|
|
33302
|
+
var AUTHORED_STATUS_COLLECTIONS = ["authored:hard", "authored:soft", "authored:variant"];
|
|
33303
|
+
async function runDeepStatusProbe(rpc, cfg) {
|
|
33304
|
+
const { userId } = resolveIdentity({
|
|
33305
|
+
configUserId: cfg.userId,
|
|
33306
|
+
identityPath: cfg.identityPath,
|
|
33307
|
+
noAutoPersist: true
|
|
33308
|
+
});
|
|
33309
|
+
const durableCollections = [`user:${userId}`, "global"];
|
|
33310
|
+
const allCollections = [...AUTHORED_STATUS_COLLECTIONS, ...durableCollections];
|
|
33301
33311
|
const probes = [];
|
|
33302
|
-
for (const collection of
|
|
33312
|
+
for (const collection of allCollections) {
|
|
33303
33313
|
try {
|
|
33304
33314
|
const result = await rpc.call("search_text", {
|
|
33305
33315
|
collection,
|
package/openclaw.plugin.json
CHANGED