Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
ensurePluginHookPolicy,
decideHookPolicy,
} from "./src/utils/ensure-hook-policy.js";
import { resolveOpenClawStateDir } from "./src/utils/openclaw-state-dir.js";

const TAG = "[memory-tdai]";

Expand Down Expand Up @@ -217,7 +218,8 @@ export default function register(api: OpenClawPluginApi) {
}

// 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);
api.logger.debug?.(`${TAG} Data dir: ${pluginDataDir} (all subdirectories initialized)`);

Expand Down Expand Up @@ -823,7 +825,7 @@ export default function register(api: OpenClawPluginApi) {
registerMemoryTdaiCli(memoryTdai, {
config,
pluginConfig: api.pluginConfig,
stateDir: api.runtime.state.resolveStateDir(),
stateDir: openclawStateDir,
logger: cliLogger,
});
},
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,12 @@
"files": [
"dist/",
"bin/",
"index.ts",
"scripts/migrate-sqlite-to-tcvdb/dist/",
"scripts/export-tencent-vdb/dist/",
"scripts/read-local-memory/dist/",
"scripts/memory-tencentdb-ctl.sh",
"scripts/install_hermes_memory_tencentdb.sh",
"scripts/README.memory-tencentdb-ctl.md",
"src/",
"scripts/openclaw-after-tool-call-messages.patch.sh",
"scripts/setup-offload.sh",
"hermes-plugin/",
Expand Down
21 changes: 21 additions & 0 deletions src/utils/openclaw-state-dir.test.ts
Original file line number Diff line number Diff line change
@@ -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"));
});
});
12 changes: 12 additions & 0 deletions src/utils/openclaw-state-dir.ts
Original file line number Diff line number Diff line change
@@ -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");
}
Loading