/**
 * Skills version tracking.
 *
 * CAAMP's skills-lock is the exclusive source of truth for skill versions.
 *
 * @epic T4454
 * @task T4521
 * @task T4680
 */
import { checkAllSkillUpdates as caampCheckAllSkillUpdates, checkSkillUpdate as caampCheckSkillUpdate, getTrackedSkills as caampGetTrackedSkills, } from '@cleocode/caamp';
/**
 * Get the installed version of a skill from CAAMP lock state.
 */
export async function getInstalledVersionAsync(name) {
    try {
        const tracked = await caampGetTrackedSkills();
        const entry = tracked[name];
        return entry?.version ?? null;
    }
    catch {
        return null;
    }
}
/**
 * Check if a specific skill needs an update via CAAMP.
 */
export async function checkSkillUpdateAsync(name) {
    try {
        const result = await caampCheckSkillUpdate(name);
        return {
            needsUpdate: result.hasUpdate,
            currentVersion: result.currentVersion,
            latestVersion: result.latestVersion,
        };
    }
    catch {
        return { needsUpdate: false };
    }
}
/**
 * Check all installed skills for available updates via CAAMP.
 */
export async function checkAllSkillUpdatesAsync() {
    try {
        const results = await caampCheckAllSkillUpdates();
        return Object.entries(results).map(([name, status]) => ({
            name,
            installedVersion: status.currentVersion ?? 'unknown',
            availableVersion: status.latestVersion ?? 'unknown',
            needsUpdate: status.hasUpdate,
        }));
    }
    catch {
        return [];
    }
}
//# sourceMappingURL=version.js.map