// resources check — reconciles each installed version's home against the DotAgents
// definitions (commands, skills, hooks, rules, mcp, plugins). This is a thin adapter
// over the existing, battle-tested heal() engine (lib/heal.ts) — no behavior change;
// it just re-expresses heal()'s result in the unified CheckResult shape.
import { resultOf } from '../types.js';
export const resourcesCheck = {
    id: 'resources',
    title: 'Resource sync (commands, skills, hooks, rules, plugins)',
    cadence: 'periodic',
    async run(ctx) {
        // Lazy import so the (heavy) heal graph only loads when this check actually runs.
        const { heal } = await import('../../heal.js');
        const result = await heal({ mode: ctx.mode, dryRun: ctx.dryRun });
        const fixed = [];
        const needsAttention = [];
        let healed = 0;
        for (const v of result.versions) {
            healed += v.healed.length;
            for (const s of v.skipped) {
                needsAttention.push(`${v.agent}@${v.version}: ${s.kind}/${s.name} (${s.reason})`);
            }
        }
        if (healed > 0)
            fixed.push(`${healed} resource(s) reconciled`);
        for (const m of result.repairedManifests) {
            fixed.push(`plugin ${m.plugin}: dropped ${m.droppedFields.join(', ')}`);
        }
        for (const p of result.refreshedPlugins) {
            fixed.push(`plugin ${p.plugin}: ${p.from} -> ${p.to}`);
        }
        for (const s of result.skippedPlugins) {
            needsAttention.push(`plugin ${s.plugin}: ${s.reason} (${s.from} vs ${s.upstream})`);
        }
        return resultOf(fixed, needsAttention);
    },
};
