// Planu — Registry Extender (SPEC-011)
// Auto-extends registries with newly discovered patterns/technologies.
// Learned entries are marked 'pending_verification' until confirmed.
const MAX_LEARNED_ENTRIES = 500;
// ── Public API ───────────────────────────────────────────────────────────────
/**
 * Detect if a name is unknown (not present in the list of existing IDs).
 * Comparison is case-insensitive and space-normalized.
 */
export function detectUnknown(name, existingIds) {
    const normalized = name.toLowerCase().replace(/\s+/g, '-');
    return !existingIds.some((id) => id.toLowerCase() === normalized);
}
/**
 * Build a new LearnedRegistryEntry for an unknown technology/pattern.
 * Entry is initially marked 'pending_verification' and unverified.
 */
export function buildLearnedEntry(name, registry, data, projectId) {
    const slug = name.toLowerCase().replace(/\s+/g, '-');
    const id = `${registry}:${slug}`;
    return {
        id,
        registry,
        data: { name, ...data },
        source: 'pending_verification',
        discoveredAt: new Date().toISOString(),
        discoveredInProject: projectId,
        verified: false,
    };
}
/**
 * Apply LRU eviction to keep the total number of learned entries under the limit.
 * Verified entries are always kept; unverified are evicted by oldest discovery.
 */
export function applyLearnedLimit(entries) {
    if (entries.length <= MAX_LEARNED_ENTRIES) {
        return entries;
    }
    const verified = entries.filter((e) => e.verified);
    const unverified = entries
        .filter((e) => !e.verified)
        .sort((a, b) => b.discoveredAt.localeCompare(a.discoveredAt));
    return [...verified, ...unverified].slice(0, MAX_LEARNED_ENTRIES);
}
/**
 * Mark an entry as verified by ID, transitioning its source to 'learned'.
 * Returns updated entries list and a flag indicating if the entry was found.
 */
export function markVerified(entries, entryId) {
    let found = false;
    const updated = entries.map((e) => {
        if (e.id === entryId) {
            found = true;
            return { ...e, verified: true, source: 'learned' };
        }
        return e;
    });
    return { updated, found };
}
//# sourceMappingURL=registry-extender.js.map