From 4487ee82aa0337f56aaa8a10d8da2905dcf0bfec Mon Sep 17 00:00:00 2001
From: "Ben.Li"
Date: Fri, 2 Oct 2026 02:35:01 +0800
Subject: [PATCH] fix: keep POSIX sibling paths out of home-relative CLI
displays (#162800)
* test: preserve POSIX backslashes at home path boundaries
* fix: preserve literal backslashes in POSIX home path displays
* test: format POSIX home boundary regression
---
src/infra/home-display.ts | 5 ++++-
src/utils.test.ts | 6 +++++-
2 files changed, 9 insertions(+), 2 deletions(-)
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");
});
});