From 5ad0c70f8e1806990ae613db06e886bc237fa645 Mon Sep 17 00:00:00 2001 From: Sebastian <19554889+sebslight@users.noreply.github.com> Date: Sun, 8 Feb 2026 16:13:01 -0500 Subject: [PATCH] fix(status): show OPENCLAW_HOME in shortened paths (#12091) (thanks @sebslight) --- src/utils.test.ts | 28 ++++++++++++++++++++++++++++ src/utils.ts | 29 +++++++++++++++++++++-------- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/src/utils.test.ts b/src/utils.test.ts index b9a88c9bbe..9bf6e00cff 100644 --- a/src/utils.test.ts +++ b/src/utils.test.ts @@ -13,6 +13,8 @@ import { resolveHomeDir, resolveJidToE164, resolveUserPath, + shortenHomeInString, + shortenHomePath, sleep, toWhatsappJid, withWhatsAppPrefix, @@ -146,6 +148,32 @@ describe("resolveHomeDir", () => { }); }); +describe("shortenHomePath", () => { + it("uses $OPENCLAW_HOME prefix when OPENCLAW_HOME is set", () => { + vi.stubEnv("OPENCLAW_HOME", "/srv/openclaw-home"); + vi.stubEnv("HOME", "/home/other"); + + expect(shortenHomePath("/srv/openclaw-home/.openclaw/openclaw.json")).toBe( + "$OPENCLAW_HOME/.openclaw/openclaw.json", + ); + + vi.unstubAllEnvs(); + }); +}); + +describe("shortenHomeInString", () => { + it("uses $OPENCLAW_HOME replacement when OPENCLAW_HOME is set", () => { + vi.stubEnv("OPENCLAW_HOME", "/srv/openclaw-home"); + vi.stubEnv("HOME", "/home/other"); + + expect(shortenHomeInString("config: /srv/openclaw-home/.openclaw/openclaw.json")).toBe( + "config: $OPENCLAW_HOME/.openclaw/openclaw.json", + ); + + vi.unstubAllEnvs(); + }); +}); + describe("resolveJidToE164", () => { it("resolves @lid via lidLookup when mapping file is missing", async () => { const lidLookup = { diff --git a/src/utils.ts b/src/utils.ts index ef416fd79e..a30264df2d 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -278,19 +278,32 @@ export function resolveHomeDir(): string | undefined { return resolveEffectiveHomeDir(process.env, os.homedir); } +function resolveHomeDisplayPrefix(): { home: string; prefix: string } | undefined { + const home = resolveHomeDir(); + if (!home) { + return undefined; + } + const explicitHome = process.env.OPENCLAW_HOME?.trim(); + if (explicitHome) { + return { home, prefix: "$OPENCLAW_HOME" }; + } + return { home, prefix: "~" }; +} + export function shortenHomePath(input: string): string { if (!input) { return input; } - const home = resolveHomeDir(); - if (!home) { + const display = resolveHomeDisplayPrefix(); + if (!display) { return input; } + const { home, prefix } = display; if (input === home) { - return "~"; + return prefix; } - if (input.startsWith(`${home}/`)) { - return `~${input.slice(home.length)}`; + if (input.startsWith(`${home}/`) || input.startsWith(`${home}\\`)) { + return `${prefix}${input.slice(home.length)}`; } return input; } @@ -299,11 +312,11 @@ export function shortenHomeInString(input: string): string { if (!input) { return input; } - const home = resolveHomeDir(); - if (!home) { + const display = resolveHomeDisplayPrefix(); + if (!display) { return input; } - return input.split(home).join("~"); + return input.split(display.home).join(display.prefix); } export function displayPath(input: string): string {