Skip to content

fix(utils): only shorten home dir when followed by path separator (#98872) - #98885

Closed
maweibin wants to merge 1 commit into
openclaw:mainfrom
maweibin:fix/display-home-path-prefix-98872
Closed

maweibin wants to merge 1 commit into
openclaw:mainfrom
maweibin:fix/display-home-path-prefix-98872

Conversation

@maweibin

@maweibin maweibin commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #98872.

What Problem This Solves

shortenHomeInString used split(home).join(prefix) to shorten home paths in display text. This matches any substring equal to the home directory — including sibling directories like /home/alice2 when home is /home/alice. The rendered path becomes ~2/project instead of /home/alice2/project.

Why This Change Was Made

Changed the split to split(home + "/") and added an exact-match case for the bare home directory. This ensures only the exact home directory or paths under it are shortened.

User Impact

Path display in terminal tables and other displayString/displayPath contexts is correct for sibling directories. No user action needed.

Evidence

Behavior addressed: shortenHomeInString corrupts sibling paths whose name shares the home prefix.

Real environment tested: Node 22.19+, local OpenClaw checkout.

Exact steps or command run after this patch:

node -e "import os from 'os'; import { shortenHomeInString } from './src/utils.js'; process.env.HOME='/home/alice'; console.log('sibling:', shortenHomeInString('/home/alice2/project')); console.log('under home:', shortenHomeInString('/home/alice/project')); console.log('exact home:', shortenHomeInString('/home/alice'));"

Evidence after fix:

sibling:   /home/alice2/project  ✅ (BEFORE: ~2/project ❌)
under home: ~/project             ✅
exact home: ~                     ✅
node scripts/run-vitest.mjs src/utils.test.ts --run
 Test Files  1 passed (1) / Tests  18 passed (18)

node scripts/run-oxlint.mjs src/utils.ts src/utils.test.ts
 (passed, exit 0)

Observed result after fix: Sibling directories with names that share the home prefix are left unchanged. Paths under the home directory continue to be shortened correctly.

What was not tested: Full terminal table rendering end-to-end. The fix is verified through unit tests and direct function invocation.

Regression Test Plan

  • node scripts/run-vitest.mjs src/utils.test.ts --run — 18 passed (+1 sibling regression test)
  • node scripts/run-oxlint.mjs src/utils.ts src/utils.test.ts — exit 0

Root Cause

shortenHomeInString line 159 used input.split(display.home).join(display.prefix) which replaces every occurrence of the home path string anywhere in the input. When home is /home/alice, the path /home/alice2/project gets split into ["", "2/project"] and joined as ~2/project. The fix splits on home + "/" so only the home directory followed by a path separator is matched.

AI Assistance

  • AI-assisted: Yes
  • Model used: Claude Opus 4.8 (1M context)
  • Co-Authored-By: Already in commit message

…enclaw#98872)

split(home) matched sibling directories whose name shares the home
prefix (e.g. /home/alice2 when home is /home/alice), corrupting
displayed paths to ~2/project.

The fix only replaces home + "/" in the input string, and handles
the exact home-directory case separately.
@clawsweeper

clawsweeper Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: fix(utils): only shorten home dir when followed by path separator (#98872) This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@maweibin

maweibin commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

Closing: #98876 fixes the correct location (packages/terminal-core/src/display-string.ts per ClawSweeper guidance). This PR fixed the wrong alias in src/utils.ts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Terminal table display rewrites paths that only share the home directory prefix

1 participant