| 1 | // @effect-diagnostics nodeBuiltinImport:off |
| 2 | import * as NodePath from "node:path"; |
| 3 | |
| 4 | /** |
| 5 | * Expand a leading `~` (or `~/…`, `~\…`) in a user-supplied path to `home`, |
| 6 | * the current user's home directory (`HostProcess.HomeDirectory`). Spawned |
| 7 | * processes don't get shell expansion, so env vars like |
| 8 | * `CODEX_HOME=~/.codex-work` would be passed verbatim and treated as relative |
| 9 | * paths by the receiver. |
| 10 | * |
| 11 | * Matches the behavior of the other `expandHomePath` helpers in the |
| 12 | * workspace layers and CLI bootstrap: `~` alone and both `~/` and `~\` |
| 13 | * separators are handled. Returns the input unchanged if it doesn't |
| 14 | * start with `~` or is empty. Does not handle `~user` (other-user) |
| 15 | * expansion. |
| 16 | */ |
| 17 | export function expandHomePath(value: string, home: string): string { |
| 18 | if (!value) return value; |
| 19 | if (value === "~") return home; |
| 20 | if (value.startsWith("~/") || value.startsWith("~\\")) { |
| 21 | return NodePath.join(home, value.slice(2)); |
| 22 | } |
| 23 | return value; |
| 24 | } |