refactor: mark legacy state file helpers

This commit is contained in:
Peter Steinberger
2026-05-08 20:41:44 +01:00
parent 21985049f3
commit d6ede36e4e
3 changed files with 16 additions and 16 deletions

View File

@@ -35,7 +35,7 @@ import { getActivePluginRegistry } from "./runtime.js";
const log = createSubsystemLogger("plugins/binding");
const APPROVALS_PATH = "~/.openclaw/plugin-binding-approvals.json";
const LEGACY_APPROVALS_PATH = "~/.openclaw/plugin-binding-approvals.json";
const APPROVALS_KV_SCOPE = "plugin_binding_approvals";
const APPROVALS_KV_KEY = "current";
const PLUGIN_BINDING_CUSTOM_ID_PREFIX = "pluginbind";
@@ -163,16 +163,16 @@ function getPluginBindingGlobalState(): PluginBindingGlobalState {
return pluginBindingGlobalState;
}
function resolveApprovalsPath(): string {
function resolveLegacyApprovalsPath(): string {
if (process.env.OPENCLAW_STATE_DIR?.trim()) {
return path.join(resolveStateDir(process.env), "plugin-binding-approvals.json");
}
return expandHomePrefix(APPROVALS_PATH);
return expandHomePrefix(LEGACY_APPROVALS_PATH);
}
function pluginBindingApprovalDbOptions(): OpenClawStateDatabaseOptions {
return {
env: { ...process.env, OPENCLAW_STATE_DIR: path.dirname(resolveApprovalsPath()) },
env: { ...process.env, OPENCLAW_STATE_DIR: path.dirname(resolveLegacyApprovalsPath()) },
};
}
@@ -451,7 +451,7 @@ async function addPersistentApproval(entry: PluginBindingApprovalEntry): Promise
export function legacyPluginBindingApprovalFileExists(): boolean {
try {
return fs.statSync(resolveApprovalsPath()).isFile();
return fs.statSync(resolveLegacyApprovalsPath()).isFile();
} catch (error) {
if ((error as NodeJS.ErrnoException)?.code === "ENOENT") {
return false;
@@ -464,7 +464,7 @@ export function importLegacyPluginBindingApprovalFileToSqlite(): {
imported: boolean;
approvals: number;
} {
const filePath = resolveApprovalsPath();
const filePath = resolveLegacyApprovalsPath();
if (!legacyPluginBindingApprovalFileExists()) {
return { imported: false, approvals: 0 };
}

View File

@@ -10,7 +10,7 @@ import {
isHeartbeatLikeTuiSession,
readTuiLastSessionKey,
resolveRememberedTuiSessionKey,
resolveTuiLastSessionStatePath,
resolveLegacyTuiLastSessionStatePath,
writeTuiLastSessionKey,
} from "./tui-last-session.js";
@@ -43,7 +43,7 @@ describe("tui last session state", () => {
});
await expect(readTuiLastSessionKey({ scopeKey, stateDir })).resolves.toBe("agent:main:tui-123");
await expect(fs.access(resolveTuiLastSessionStatePath(stateDir))).rejects.toMatchObject({
await expect(fs.access(resolveLegacyTuiLastSessionStatePath(stateDir))).rejects.toMatchObject({
code: "ENOENT",
});
});
@@ -61,7 +61,7 @@ describe("tui last session state", () => {
sessionKey: "agent:main:tui-sqlite",
stateDir,
});
await expect(fs.access(resolveTuiLastSessionStatePath(stateDir))).rejects.toMatchObject({
await expect(fs.access(resolveLegacyTuiLastSessionStatePath(stateDir))).rejects.toMatchObject({
code: "ENOENT",
});
@@ -77,7 +77,7 @@ describe("tui last session state", () => {
agentId: "main",
sessionScope: "per-sender",
});
const statePath = resolveTuiLastSessionStatePath(stateDir);
const statePath = resolveLegacyTuiLastSessionStatePath(stateDir);
await fs.mkdir(path.dirname(statePath), { recursive: true });
await fs.writeFile(
statePath,
@@ -97,7 +97,7 @@ describe("tui last session state", () => {
it("removes empty legacy JSON through the doctor migration helper", async () => {
const stateDir = await makeTempStateDir();
const statePath = resolveTuiLastSessionStatePath(stateDir);
const statePath = resolveLegacyTuiLastSessionStatePath(stateDir);
await fs.mkdir(path.dirname(statePath), { recursive: true });
await fs.writeFile(statePath, "{}\n", "utf8");
@@ -135,7 +135,7 @@ describe("tui last session state", () => {
agentId: "main",
sessionScope: "per-sender",
});
const statePath = resolveTuiLastSessionStatePath(stateDir);
const statePath = resolveLegacyTuiLastSessionStatePath(stateDir);
await fs.mkdir(path.dirname(statePath), { recursive: true });
await fs.writeFile(
statePath,

View File

@@ -22,7 +22,7 @@ type LastSessionRecord = {
type LastSessionStore = Record<string, LastSessionRecord>;
const TUI_LAST_SESSION_KV_SCOPE = "tui:last-session";
export function resolveTuiLastSessionStatePath(stateDir = resolveStateDir()): string {
export function resolveLegacyTuiLastSessionStatePath(stateDir = resolveStateDir()): string {
return path.join(stateDir, "tui", "last-session.json");
}
@@ -89,7 +89,7 @@ function writeTuiLastSessionKv(params: {
async function readLegacyTuiLastSessionStore(params: {
stateDir?: string;
}): Promise<LastSessionStore> {
const filePath = resolveTuiLastSessionStatePath(params.stateDir);
const filePath = resolveLegacyTuiLastSessionStatePath(params.stateDir);
return await readStore(filePath);
}
@@ -99,7 +99,7 @@ export async function legacyTuiLastSessionFileExists(
} = {},
): Promise<boolean> {
try {
await fs.access(resolveTuiLastSessionStatePath(params.stateDir));
await fs.access(resolveLegacyTuiLastSessionStatePath(params.stateDir));
return true;
} catch {
return false;
@@ -111,7 +111,7 @@ export async function importLegacyTuiLastSessionStoreToSqlite(
stateDir?: string;
} = {},
): Promise<{ imported: boolean; pointers: number }> {
const filePath = resolveTuiLastSessionStatePath(params.stateDir);
const filePath = resolveLegacyTuiLastSessionStatePath(params.stateDir);
const exists = await legacyTuiLastSessionFileExists(params);
if (!exists) {
return { imported: false, pointers: 0 };