import { readFileSync } from "node:fs"; import { homedir } from "node:os"; import { join } from "node:path"; export function getGlobalEnvPath(homeDir = homedir()): string { return join(homeDir, ".pi", "agent", ".env"); } export interface GlobalEnvFile { exists: boolean; path: string; content?: string; } function tryReadEnvFile(filePath: string): GlobalEnvFile { try { return { exists: true, path: filePath, content: readFileSync(filePath, "utf8"), }; } catch (error) { const err = error as NodeJS.ErrnoException; if (err.code === "ENOENT") { return { exists: false, path: filePath }; } throw error; } } export function readGlobalEnvFile(filePath = getGlobalEnvPath()): GlobalEnvFile { return tryReadEnvFile(filePath); }