fix sessions dir from state env

what: use CLAWDBOT_STATE_DIR/CLAWDIS_STATE_DIR for session transcripts

why: isolate multi-instance gateways

tests: not run
This commit is contained in:
Josh Palmer
2026-01-05 00:51:01 +01:00
parent 59dfe0337d
commit aa45f512f4
3 changed files with 26 additions and 4 deletions

View File

@@ -27,8 +27,9 @@ export function resolveStateDir(
env: NodeJS.ProcessEnv = process.env, env: NodeJS.ProcessEnv = process.env,
homedir: () => string = os.homedir, homedir: () => string = os.homedir,
): string { ): string {
const override = env.CLAWDBOT_STATE_DIR?.trim(); const override =
if (override) return override; env.CLAWDBOT_STATE_DIR?.trim() || env.CLAWDIS_STATE_DIR?.trim();
if (override) return resolveUserPath(override);
return path.join(homedir(), ".clawdbot"); return path.join(homedir(), ".clawdbot");
} }

View File

@@ -8,6 +8,7 @@ import {
deriveSessionKey, deriveSessionKey,
loadSessionStore, loadSessionStore,
resolveSessionKey, resolveSessionKey,
resolveSessionTranscriptsDir,
updateLastRoute, updateLastRoute,
} from "./sessions.js"; } from "./sessions.js";
@@ -127,4 +128,20 @@ describe("sessions", () => {
expect(store.main?.lastChannel).toBe("telegram"); expect(store.main?.lastChannel).toBe("telegram");
expect(store.main?.lastTo).toBe("12345"); expect(store.main?.lastTo).toBe("12345");
}); });
it("derives session transcripts dir from CLAWDBOT_STATE_DIR", () => {
const dir = resolveSessionTranscriptsDir(
{ CLAWDBOT_STATE_DIR: "/custom/state" } as NodeJS.ProcessEnv,
() => "/home/ignored",
);
expect(dir).toBe("/custom/state/sessions");
});
it("falls back to CLAWDIS_STATE_DIR for session transcripts dir", () => {
const dir = resolveSessionTranscriptsDir(
{ CLAWDIS_STATE_DIR: "/legacy/state" } as NodeJS.ProcessEnv,
() => "/home/ignored",
);
expect(dir).toBe("/legacy/state/sessions");
});
}); });

View File

@@ -7,6 +7,7 @@ import type { Skill } from "@mariozechner/pi-coding-agent";
import JSON5 from "json5"; import JSON5 from "json5";
import type { MsgContext } from "../auto-reply/templating.js"; import type { MsgContext } from "../auto-reply/templating.js";
import { normalizeE164 } from "../utils.js"; import { normalizeE164 } from "../utils.js";
import { resolveStateDir } from "./paths.js";
export type SessionScope = "per-sender" | "global"; export type SessionScope = "per-sender" | "global";
@@ -84,8 +85,11 @@ export type SessionSkillSnapshot = {
resolvedSkills?: Skill[]; resolvedSkills?: Skill[];
}; };
export function resolveSessionTranscriptsDir(): string { export function resolveSessionTranscriptsDir(
return path.join(os.homedir(), ".clawdbot", "sessions"); env: NodeJS.ProcessEnv = process.env,
homedir: () => string = os.homedir,
): string {
return path.join(resolveStateDir(env, homedir), "sessions");
} }
export function resolveDefaultSessionStorePath(): string { export function resolveDefaultSessionStorePath(): string {