import fs from "node:fs/promises";
import path from "node:path";
import { LISA_HOME } from "../paths.js";
import { pathExists } from "../fs-utils.js";
/** Default per-run token ceiling when heartbeat.json doesn't set one. */
export const DEFAULT_HEARTBEAT_BUDGET_TOKENS = 500_000;
const FILE = path.join(LISA_HOME, "heartbeat.json");
export async function loadHeartbeatConfig() {
    if (!(await pathExists(FILE)))
        return { tasks: [], budgetTokens: DEFAULT_HEARTBEAT_BUDGET_TOKENS };
    const raw = await fs.readFile(FILE, "utf8");
    let parsed;
    try {
        parsed = JSON.parse(raw);
    }
    catch (err) {
        throw new Error(`failed to parse ${FILE}: ${err.message}`);
    }
    return {
        tasks: parsed.tasks ?? [],
        // Explicit 0 means "no limit"; undefined means "use the default ceiling".
        budgetTokens: parsed.budgetTokens === undefined ? DEFAULT_HEARTBEAT_BUDGET_TOKENS : parsed.budgetTokens,
    };
}
export const HEARTBEAT_CONFIG_PATH = FILE;
//# sourceMappingURL=config.js.map