import * as OS from "node:os"; import { Effect, Path } from "effect"; import { readPathFromLoginShell, resolveLoginShell } from "@t3tools/shared/shell"; export function fixPath( options: { env?: NodeJS.ProcessEnv; platform?: NodeJS.Platform; readPath?: typeof readPathFromLoginShell; } = {}, ): void { const platform = options.platform ?? process.platform; if (platform !== "darwin" && platform !== "linux") return; const env = options.env ?? process.env; try { const shell = resolveLoginShell(platform, env.SHELL); if (!shell) return; const result = (options.readPath ?? readPathFromLoginShell)(shell); if (result) { env.PATH = result; } } catch { // Silently ignore — keep default PATH } } export const expandHomePath = Effect.fn(function* (input: string) { const { join } = yield* Path.Path; if (input === "~") { return OS.homedir(); } if (input.startsWith("~/") || input.startsWith("~\\")) { return join(OS.homedir(), input.slice(2)); } return input; }); export const resolveBaseDir = Effect.fn(function* (raw: string | undefined) { const { join, resolve } = yield* Path.Path; if (!raw || raw.trim().length === 0) { return join(OS.homedir(), ".t3"); } return resolve(yield* expandHomePath(raw.trim())); });