diff --git a/src/infra/home-display.ts b/src/infra/home-display.ts index a11ea986ed77..0a2e870e9be8 100644 --- a/src/infra/home-display.ts +++ b/src/infra/home-display.ts @@ -10,7 +10,10 @@ export function shortenPathWithHome( if (input === home) { return prefix; } - if (input.startsWith(`${home}/`) || input.startsWith(`${home}\\`)) { + if ( + input.startsWith(`${home}/`) || + (process.platform === "win32" && input.startsWith(`${home}\\`)) + ) { return `${prefix}${input.slice(home.length)}`; } if (process.platform === "win32" && path.win32.isAbsolute(input) && isPathInside(home, input)) { diff --git a/src/utils.test.ts b/src/utils.test.ts index 785616e3df71..d0b63c6381a5 100644 --- a/src/utils.test.ts +++ b/src/utils.test.ts @@ -173,9 +173,13 @@ describe("shortenHomePath", () => { }, ); - it.skipIf(process.platform === "win32")("keeps POSIX home matching case-sensitive", () => { + it.skipIf(process.platform === "win32")("preserves POSIX home path boundaries and case", () => { withEnv({ OPENCLAW_HOME: "/srv/OpenClaw-Home", HOME: "/home/other" }, () => { expect(shortenHomePath("/srv/openclaw-home/workspace")).toBe("/srv/openclaw-home/workspace"); + expect(shortenHomePath("/srv/OpenClaw-Home\\workspace")).toBe( + "/srv/OpenClaw-Home\\workspace", + ); + expect(shortenHomePath("/srv/OpenClaw-Home/work\\space")).toBe("$OPENCLAW_HOME/work\\space"); }); });