"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.findLatestPlanFile = findLatestPlanFile;
exports.readPlanFile = readPlanFile;
const node_fs_1 = require("node:fs");
const node_path_1 = require("node:path");
const paths_1 = require("../server/paths");
function plansDir() {
    return (0, node_path_1.join)((0, paths_1.getClaudeDir)(), "plans");
}
function findLatestPlanFile() {
    try {
        const dir = plansDir();
        const files = (0, node_fs_1.readdirSync)(dir).filter((f) => f.endsWith(".md") && !f.includes("-agent-"));
        if (files.length === 0)
            return undefined;
        let latest = files[0];
        let latestMtime = 0;
        for (const f of files) {
            const mtime = (0, node_fs_1.statSync)((0, node_path_1.join)(dir, f)).mtimeMs;
            if (mtime > latestMtime) {
                latestMtime = mtime;
                latest = f;
            }
        }
        return (0, node_path_1.join)(dir, latest);
    }
    catch {
        return undefined;
    }
}
function readPlanFile(path) {
    try {
        return (0, node_fs_1.readFileSync)(path, "utf-8");
    }
    catch {
        return undefined;
    }
}
