// ---------------------------------------------------------------------------
// activation-history.ts -- persistent activation test history per skill
// ---------------------------------------------------------------------------
import { readFile, writeFile, mkdir } from "node:fs/promises";
import { join } from "node:path";
const HISTORY_FILENAME = "activation-history.json";
const MAX_RUNS = 50;
function historyPath(skillDir) {
    return join(skillDir, HISTORY_FILENAME);
}
async function readHistoryFile(skillDir) {
    try {
        const content = await readFile(historyPath(skillDir), "utf-8");
        const parsed = JSON.parse(content);
        if (parsed && Array.isArray(parsed.runs))
            return parsed;
        return { runs: [] };
    }
    catch {
        return { runs: [] };
    }
}
export async function writeActivationRun(skillDir, run) {
    await mkdir(skillDir, { recursive: true });
    const history = await readHistoryFile(skillDir);
    history.runs.push(run);
    // Prune oldest if over cap
    if (history.runs.length > MAX_RUNS) {
        history.runs = history.runs.slice(history.runs.length - MAX_RUNS);
    }
    await writeFile(historyPath(skillDir), JSON.stringify(history, null, 2));
}
export async function listActivationRuns(skillDir) {
    const history = await readHistoryFile(skillDir);
    return history.runs.map(({ results: _results, ...rest }) => rest).reverse();
}
export async function getActivationRun(skillDir, runId) {
    const history = await readHistoryFile(skillDir);
    return history.runs.find((r) => r.id === runId) ?? null;
}
//# sourceMappingURL=activation-history.js.map