← Back to PRs

#20024: Use expandHomePrefix for consistent tilde expansion

by Clawborn open 2026-02-18 12:06 View on GitHub →
channel: imessage size: XS trusted-contributor
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