#20024: Use expandHomePrefix for consistent tilde expansion
channel: imessage
size: XS
trusted-contributor
Cluster:
Workspace Path Fixes
Two files manually expand `~` using `process.env.HOME` with ad-hoc string replacements:
- `commands-export-session.ts`: `args.outputPath.replace("~", process.env.HOME ?? "")`
- `monitor-provider.ts`: `cliPath.replace(/^~/, process.env.HOME ?? "")`
When `HOME` is unset, the replacement produces root-relative paths (e.g. `/foo` instead of `~/foo`). These also ignore `OPENCLAW_HOME` overrides and Windows `USERPROFILE` fallbacks.
Replace with the existing `expandHomePrefix` helper from `infra/home-dir.ts` which handles all edge cases.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Replaces two ad-hoc `~` expansion patterns (`process.env.HOME` string replacement) with the existing `expandHomePrefix` helper from `infra/home-dir.ts`. This fixes edge cases where `HOME` is unset (previously produced root-relative paths), respects `OPENCLAW_HOME` overrides and Windows `USERPROFILE` fallbacks, and ensures consistency with the rest of the codebase which already uses this utility.
- `commands-export-session.ts`: Replaced inline tilde expansion with `expandHomePrefix` for output path resolution
- `monitor-provider.ts`: Replaced inline tilde expansion with `expandHomePrefix` for CLI path detection
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge — it replaces ad-hoc logic with an existing, well-tested utility function.
- Minimal, focused refactor that replaces two instances of ad-hoc tilde expansion with the existing `expandHomePrefix` helper. The helper is already used in 5+ other places in the codebase and is well-tested. No new behavior is introduced, and the change strictly improves edge-case handling.
- No files require special attention.
<sub>Last reviewed commit: 8116b47</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#17815: fix: use $HOME as cwd for global update to prevent path-dedot panic
by frankekn · 2026-02-16
75.8%
#11529: fix(wizard): strip shell-style backslash escapes from workspace paths
by mcaxtr · 2026-02-07
75.6%
#13497: fix(docker): normalize workspace paths for container compatibility
by janckerchen · 2026-02-10
72.8%
#10714: fix: handle Windows PATH case-sensitivity in node register invoke
by Yida-Dev · 2026-02-06
72.6%
#7764: Rename escape function for double quotes
by voku · 2026-02-03
71.9%
#10708: fix: handle Windows PATH case-sensitivity in exec environment
by Yida-Dev · 2026-02-06
71.7%
#13848: fix(test): normalize paths in source-display test for windows
by gengmao · 2026-02-11
71.6%
#20640: fix: prevent zsh glob expansion errors in exec commands
by okuyam2y · 2026-02-19
71.5%
#19931: Config: merge PATH env vars and bootstrap Windows bins
by Kemalau · 2026-02-18
71.3%
#23480: fix(test): use path.join for cross-platform XDG path assertions in ...
by hydro13 · 2026-02-22
71.1%