google-gemini / google-gemini/gemini-cli
Bug: tildeifyPath treats sibling home directories as the current home (missing path-separator bound)
- Dominant language
- TypeScript
- Stars
- 107k
- Forks
- 14.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 45
Description
### What happened?
`tildeifyPath()` uses `path.startsWith(homeDir)` and then `path.replace(homeDir, '~')`. There is no check that the match is a full path segment.
If `homedir()` is `/Users/al` (or `C:\Users\Al` on Windows):
- `/Users/al/proj` → `~/proj` (correct)
- `/Users/albert/proj` → `~bert/proj` (wrong)
- `/Users/al` → `~` (correct)
`startsWith('/Users/al')` is true for `/Users/albert/...`, so a different user's (or a longer username's) directory is displayed as under `~`.
Used in the CLI footer and background-task display (`Footer.tsx`, `BackgroundTaskDisplay.tsx`). `packages/core/src/utils/paths.test.ts` never tests this function.
Repro (unit-level):
1. Stub `homedir()` / `GEMINI_CLI_HOME` to `/Users/al`.
2. Call `tildeifyPath('/Users/albert/Documents/app')`.
3. Actual: `~bert/Documents/app`. Expected: `/Users/albert/Documents/app` unchanged.
### What did you expect to happen?
Only the home directory itself, or paths under `home + path.sep`, should be tilde-prefixed.
Sibling prefixes (`/Users/albert` when home is `/Users/al`) must be left unchanged.
### Client information
Reproduced from source on current `main`. Platform: macOS.
CLI Version: 0.59.0-nightly.20260825.g812f7a2bc
### Login information
Not auth-related. Display-path helper in packages/core/src/utils/paths.ts.
### Anything else we need to know?
Suggested fix: treat as home only when
`p === home` or `p.startsWith(home + path.sep)`
(and on Windows also `home + '/'` if callers pass forward slashes). Then replace that exact prefix with `~`.
Add unit tests in `paths.test.ts` for:
- exact home → `~`
- child of home → `~/...`
- sibling prefix (`/Users/al` vs `/Users/albert`) → unchanged
- Windows `C:\Users\Al` vs `C:\Users\Albert`
I'd like to send a focused PR with tests after this is labeled `help wanted`.
Contributor guide
Research direction
Start in packages/core/src/utils/paths.ts and inspect the tildeifyPath() implementation and its callers in Footer.tsx and BackgroundTaskDisplay.tsx. Add focused coverage in packages/core/src/utils/paths.test.ts for exact home paths, child paths, sibling prefixes, and Windows paths; done means only the home directory and its descendants are tilde-prefixed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 88/100