"use strict";
// Brief scheduler helper.
//
// Pure snapshot function the existing automation scheduler can call to produce
// a daily/evening brief without coupling jarvis to the scheduler module.
Object.defineProperty(exports, "__esModule", { value: true });
exports.snapshotDailyBrief = snapshotDailyBrief;
const sessionLearning_1 = require("../learning/sessionLearning");
const evidenceStore_1 = require("../persistence/evidenceStore");
const dailyBrief_1 = require("./dailyBrief");
const knowledgeGraph_1 = require("./knowledgeGraph");
const predictiveEngine_1 = require("./predictiveEngine");
const predictiveAdapter_1 = require("./predictiveAdapter");
const trustLadder_1 = require("./trustLadder");
async function snapshotDailyBrief(options) {
    const { projectDir } = options;
    const ambientSignals = options.ambientSignals ?? [];
    const [trust, knowledge, candidates, runs] = await Promise.all([
        (0, trustLadder_1.loadTrustLadder)(projectDir),
        (0, knowledgeGraph_1.getKnowledgeGraphStatus)(projectDir),
        (0, sessionLearning_1.listLearningCandidates)(projectDir, 20).catch(() => []),
        (0, evidenceStore_1.readRunEvidence)(projectDir, 50).catch(() => []),
    ]);
    const events = (0, predictiveAdapter_1.mergeAndSort)((0, predictiveAdapter_1.eventsFromAmbientSignals)(ambientSignals), (0, predictiveAdapter_1.eventsFromEvidenceCards)(runs));
    const predictiveSuggestions = (0, predictiveEngine_1.mineNextActions)(events, { limit: 8 });
    const evidenceSummaries = runs.slice(0, 10).map((r) => ({ title: oneLine(r.request), status: r.kind, at: r.createdAt }));
    const markdown = (0, dailyBrief_1.composeDailyBrief)({
        asOf: new Date().toISOString(),
        windowDescription: options.windowDescription ?? 'snapshot',
        ambientSignals,
        pendingLearningCandidates: candidates.map((c) => ({ id: c.id, prompt: c.prompt, outcome: c.outcome, createdAt: c.createdAt })),
        predictiveSuggestions,
        knowledgeGraph: knowledge,
        trustLadder: trust,
        evidenceSummaries,
    });
    return { generatedAt: new Date().toISOString(), markdown };
}
function oneLine(text, max = 80) {
    const cleaned = (text || '').replace(/\s+/g, ' ').trim();
    return cleaned.length <= max ? cleaned : cleaned.slice(0, max - 1) + '…';
}
//# sourceMappingURL=briefScheduler.js.map