fix: use STATE_DIR instead of hardcoded ~/.openclaw for identity and canvas (#4824)

* fix: use STATE_DIR instead of hardcoded ~/.openclaw for identity and canvas

device-identity.ts and canvas-host/server.ts used hardcoded
path.join(os.homedir(), '.openclaw', ...) ignoring OPENCLAW_STATE_DIR
env var and the resolveStateDir() logic from config/paths.ts.

This caused ~/.openclaw/identity and ~/.openclaw/canvas directories
to be created even when state dir was overridden or resided elsewhere.

* fix: format and remove duplicate imports

* fix: scope state-dir patch + add regression tests (#4824) (thanks @kossoy)

* fix: align state-dir fallbacks in hooks and agent paths (#4824) (thanks @kossoy)

---------

Co-authored-by: Gustavo Madeira Santana <gumadeiras@gmail.com>
This commit is contained in:
Oleg Kossoy
2026-02-08 05:16:59 +02:00
committed by GitHub
parent 0499656c59
commit ebe5730401
13 changed files with 140 additions and 16 deletions

View File

@@ -1,7 +1,7 @@
import crypto from "node:crypto";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { STATE_DIR } from "../config/paths.js";
export type DeviceIdentity = {
deviceId: string;
@@ -17,7 +17,7 @@ type StoredIdentity = {
createdAtMs: number;
};
const DEFAULT_DIR = path.join(os.homedir(), ".openclaw", "identity");
const DEFAULT_DIR = path.join(STATE_DIR, "identity");
const DEFAULT_FILE = path.join(DEFAULT_DIR, "device.json");
function ensureDir(filePath: string) {