1// @effect-diagnostics nodeBuiltinImport:off
2import * as NodePath from "node:path";
3
4// Spawned processes lack shell expansion and would treat literal ~/ paths as relative.
5export function expandHomePath(value: string, home: string): string {
6 if (!value) return value;
7 if (value === "~") return home;
8 if (value.startsWith("~/") || value.startsWith("~\\")) {
9 return NodePath.join(home, value.slice(2));
10 }
11 return value;
12}
13
14const HOME_PATH_VARIABLES = new Set(["CODEX_HOME", "CLAUDE_CONFIG_DIR", "GROK_HOME"]);
15
16export function expandHomeVariable(name: string, value: string, home: string): string {
17 return HOME_PATH_VARIABLES.has(name) ? expandHomePath(value, home) : value;
18}