diff --git a/src/daemon/paths.test.ts b/src/daemon/paths.test.ts index 3d6bca1a6..2b3ba143c 100644 --- a/src/daemon/paths.test.ts +++ b/src/daemon/paths.test.ts @@ -34,4 +34,23 @@ describe("resolveGatewayStateDir", () => { const env = { CLAWDBOT_STATE_DIR: "C:\\State\\moltbot" }; expect(resolveGatewayStateDir(env)).toBe("C:\\State\\moltbot"); }); + + it("uses MOLTBOT_STATE_DIR when provided", () => { + const env = { HOME: "/Users/test", MOLTBOT_STATE_DIR: "/var/lib/moltbot" }; + expect(resolveGatewayStateDir(env)).toBe(path.resolve("/var/lib/moltbot")); + }); + + it("prefers MOLTBOT_STATE_DIR over CLAWDBOT_STATE_DIR", () => { + const env = { + HOME: "/Users/test", + MOLTBOT_STATE_DIR: "/var/lib/moltbot-new", + CLAWDBOT_STATE_DIR: "/var/lib/moltbot-old", + }; + expect(resolveGatewayStateDir(env)).toBe(path.resolve("/var/lib/moltbot-new")); + }); + + it("expands ~ in MOLTBOT_STATE_DIR", () => { + const env = { HOME: "/Users/test", MOLTBOT_STATE_DIR: "~/.moltbot" }; + expect(resolveGatewayStateDir(env)).toBe(path.resolve("/Users/test/.moltbot")); + }); }); diff --git a/src/daemon/paths.ts b/src/daemon/paths.ts index 61913fe3c..659e278ed 100644 --- a/src/daemon/paths.ts +++ b/src/daemon/paths.ts @@ -26,7 +26,7 @@ export function resolveUserPathWithHome(input: string, home?: string): string { } export function resolveGatewayStateDir(env: Record): string { - const override = env.CLAWDBOT_STATE_DIR?.trim(); + const override = env.MOLTBOT_STATE_DIR?.trim() || env.CLAWDBOT_STATE_DIR?.trim(); if (override) { const home = override.startsWith("~") ? resolveHomeDir(env) : undefined; return resolveUserPathWithHome(override, home); diff --git a/src/daemon/service-env.ts b/src/daemon/service-env.ts index 776080ebe..e660e418a 100644 --- a/src/daemon/service-env.ts +++ b/src/daemon/service-env.ts @@ -140,6 +140,7 @@ export function buildServiceEnvironment(params: { HOME: env.HOME, PATH: buildMinimalServicePath({ env }), CLAWDBOT_PROFILE: profile, + MOLTBOT_STATE_DIR: env.MOLTBOT_STATE_DIR, CLAWDBOT_STATE_DIR: env.CLAWDBOT_STATE_DIR, CLAWDBOT_CONFIG_PATH: env.CLAWDBOT_CONFIG_PATH, CLAWDBOT_GATEWAY_PORT: String(port), @@ -159,6 +160,7 @@ export function buildNodeServiceEnvironment(params: { return { HOME: env.HOME, PATH: buildMinimalServicePath({ env }), + MOLTBOT_STATE_DIR: env.MOLTBOT_STATE_DIR, CLAWDBOT_STATE_DIR: env.CLAWDBOT_STATE_DIR, CLAWDBOT_CONFIG_PATH: env.CLAWDBOT_CONFIG_PATH, CLAWDBOT_LAUNCHD_LABEL: resolveNodeLaunchAgentLabel(),