mirror of
https://github.com/TencentCloud/TencentDB-Agent-Memory
synced 2026-07-10 12:34:27 +00:00
fix(plugin): add OpenClaw state dir fallback
This commit is contained in:
@@ -42,6 +42,7 @@ import {
|
|||||||
ensurePluginHookPolicy,
|
ensurePluginHookPolicy,
|
||||||
decideHookPolicy,
|
decideHookPolicy,
|
||||||
} from "./src/utils/ensure-hook-policy.js";
|
} from "./src/utils/ensure-hook-policy.js";
|
||||||
|
import { resolveOpenClawStateDir } from "./src/utils/openclaw-state-dir.js";
|
||||||
|
|
||||||
const TAG = "[memory-tdai]";
|
const TAG = "[memory-tdai]";
|
||||||
|
|
||||||
@@ -217,7 +218,8 @@ export default function register(api: OpenClawPluginApi) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Resolve plugin data directory via runtime API (avoid importing internal paths directly)
|
// Resolve plugin data directory via runtime API (avoid importing internal paths directly)
|
||||||
const pluginDataDir = path.join(api.runtime.state.resolveStateDir(), "memory-tdai");
|
const openclawStateDir = resolveOpenClawStateDir(api.runtime.state);
|
||||||
|
const pluginDataDir = path.join(openclawStateDir, "memory-tdai");
|
||||||
initDataDirectories(pluginDataDir);
|
initDataDirectories(pluginDataDir);
|
||||||
api.logger.debug?.(`${TAG} Data dir: ${pluginDataDir} (all subdirectories initialized)`);
|
api.logger.debug?.(`${TAG} Data dir: ${pluginDataDir} (all subdirectories initialized)`);
|
||||||
|
|
||||||
@@ -823,7 +825,7 @@ export default function register(api: OpenClawPluginApi) {
|
|||||||
registerMemoryTdaiCli(memoryTdai, {
|
registerMemoryTdaiCli(memoryTdai, {
|
||||||
config,
|
config,
|
||||||
pluginConfig: api.pluginConfig,
|
pluginConfig: api.pluginConfig,
|
||||||
stateDir: api.runtime.state.resolveStateDir(),
|
stateDir: openclawStateDir,
|
||||||
logger: cliLogger,
|
logger: cliLogger,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -34,14 +34,12 @@
|
|||||||
"files": [
|
"files": [
|
||||||
"dist/",
|
"dist/",
|
||||||
"bin/",
|
"bin/",
|
||||||
"index.ts",
|
|
||||||
"scripts/migrate-sqlite-to-tcvdb/dist/",
|
"scripts/migrate-sqlite-to-tcvdb/dist/",
|
||||||
"scripts/export-tencent-vdb/dist/",
|
"scripts/export-tencent-vdb/dist/",
|
||||||
"scripts/read-local-memory/dist/",
|
"scripts/read-local-memory/dist/",
|
||||||
"scripts/memory-tencentdb-ctl.sh",
|
"scripts/memory-tencentdb-ctl.sh",
|
||||||
"scripts/install_hermes_memory_tencentdb.sh",
|
"scripts/install_hermes_memory_tencentdb.sh",
|
||||||
"scripts/README.memory-tencentdb-ctl.md",
|
"scripts/README.memory-tencentdb-ctl.md",
|
||||||
"src/",
|
|
||||||
"scripts/openclaw-after-tool-call-messages.patch.sh",
|
"scripts/openclaw-after-tool-call-messages.patch.sh",
|
||||||
"scripts/setup-offload.sh",
|
"scripts/setup-offload.sh",
|
||||||
"hermes-plugin/",
|
"hermes-plugin/",
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import { homedir } from "node:os";
|
||||||
|
import path from "node:path";
|
||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
import { resolveOpenClawStateDir } from "./openclaw-state-dir.js";
|
||||||
|
|
||||||
|
describe("resolveOpenClawStateDir", () => {
|
||||||
|
it("uses the runtime state resolver when available", () => {
|
||||||
|
const stateDir = resolveOpenClawStateDir({
|
||||||
|
resolveStateDir: () => "/tmp/openclaw-state",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(stateDir).toBe("/tmp/openclaw-state");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("falls back to ~/.openclaw when runtime.state is not available", () => {
|
||||||
|
const stateDir = resolveOpenClawStateDir(undefined);
|
||||||
|
|
||||||
|
expect(stateDir).toBe(path.join(homedir(), ".openclaw"));
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { homedir } from "node:os";
|
||||||
|
import path from "node:path";
|
||||||
|
|
||||||
|
export interface OpenClawRuntimeStateLike {
|
||||||
|
resolveStateDir?: () => string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resolveOpenClawStateDir(
|
||||||
|
runtimeState: OpenClawRuntimeStateLike | undefined,
|
||||||
|
): string {
|
||||||
|
return runtimeState?.resolveStateDir?.() ?? path.join(homedir(), ".openclaw");
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user