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:
@@ -27,8 +27,9 @@ export function resolveStateDir(
|
||||
env: NodeJS.ProcessEnv = process.env,
|
||||
homedir: () => string = os.homedir,
|
||||
): string {
|
||||
const override = env.CLAWDBOT_STATE_DIR?.trim();
|
||||
if (override) return override;
|
||||
const override =
|
||||
env.CLAWDBOT_STATE_DIR?.trim() || env.CLAWDIS_STATE_DIR?.trim();
|
||||
if (override) return resolveUserPath(override);
|
||||
return path.join(homedir(), ".clawdbot");
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
deriveSessionKey,
|
||||
loadSessionStore,
|
||||
resolveSessionKey,
|
||||
resolveSessionTranscriptsDir,
|
||||
updateLastRoute,
|
||||
} from "./sessions.js";
|
||||
|
||||
@@ -127,4 +128,20 @@ describe("sessions", () => {
|
||||
expect(store.main?.lastChannel).toBe("telegram");
|
||||
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");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,6 +7,7 @@ import type { Skill } from "@mariozechner/pi-coding-agent";
|
||||
import JSON5 from "json5";
|
||||
import type { MsgContext } from "../auto-reply/templating.js";
|
||||
import { normalizeE164 } from "../utils.js";
|
||||
import { resolveStateDir } from "./paths.js";
|
||||
|
||||
export type SessionScope = "per-sender" | "global";
|
||||
|
||||
@@ -84,8 +85,11 @@ export type SessionSkillSnapshot = {
|
||||
resolvedSkills?: Skill[];
|
||||
};
|
||||
|
||||
export function resolveSessionTranscriptsDir(): string {
|
||||
return path.join(os.homedir(), ".clawdbot", "sessions");
|
||||
export function resolveSessionTranscriptsDir(
|
||||
env: NodeJS.ProcessEnv = process.env,
|
||||
homedir: () => string = os.homedir,
|
||||
): string {
|
||||
return path.join(resolveStateDir(env, homedir), "sessions");
|
||||
}
|
||||
|
||||
export function resolveDefaultSessionStorePath(): string {
|
||||
|
||||
Reference in New Issue
Block a user