1import { resolve } from "node:path";
2
3/**
4 * Expand a leading ~ in a file path to the user's home directory.
5 * Use for paths outside the workspace (e.g. system_prompt_path).
6 * Workspace-sandboxed paths should NOT use this.
7 */
8export function expandHomePath(filePath: string): string {
9 const home = process.env["HOME"];
10 if (!home) return filePath;
11
12 if (filePath === "~") return home;
13 if (filePath.startsWith("~/")) return resolve(home, filePath.slice(2));
14
15 return filePath;
16}