import { existsSync, readFileSync } from "node:fs";
import { homedir } from "node:os";
import path from "node:path";
export function resolvePaseoHome(env = process.env) {
    const raw = env.PASEO_HOME?.trim();
    if (!raw) {
        return path.join(homedir(), ".paseo");
    }
    if (raw === "~") {
        return homedir();
    }
    if (raw.startsWith("~/")) {
        return path.join(homedir(), raw.slice(2));
    }
    return raw;
}
export function readConfigListen(home) {
    const configPath = path.join(home, "config.json");
    if (!existsSync(configPath)) {
        return null;
    }
    try {
        const parsed = JSON.parse(readFileSync(configPath, "utf8"));
        const listen = parsed.daemon?.listen?.trim();
        return listen || null;
    }
    catch {
        return null;
    }
}
