"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.findLatestPlanFile = findLatestPlanFile;
exports.readPlanFile = readPlanFile;
const node_fs_1 = require("node:fs");
const node_os_1 = require("node:os");
const node_path_1 = require("node:path");
const PLANS_DIR = (0, node_path_1.join)((0, node_os_1.homedir)(), ".claude", "plans");
function findLatestPlanFile() {
    try {
        const files = (0, node_fs_1.readdirSync)(PLANS_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)(PLANS_DIR, f)).mtimeMs;
            if (mtime > latestMtime) {
                latestMtime = mtime;
                latest = f;
            }
        }
        return (0, node_path_1.join)(PLANS_DIR, latest);
    }
    catch {
        return undefined;
    }
}
function readPlanFile(path) {
    try {
        return (0, node_fs_1.readFileSync)(path, "utf-8");
    }
    catch {
        return undefined;
    }
}
