/** In-memory registry mapping agentId → AgentCapability. */
const registry = new Map();
/**
 * Register (or replace) an agent capability entry.
 * C1: Stores agent capability indexed by agentId.
 * C2: Capability shape includes role, ecosystems, filePatterns, maxConcurrency, preferredModel.
 */
export function registerCapability(agentId, capability) {
    registry.set(agentId, { ...capability, agentId });
}
/**
 * Return the capability for a specific agent, or undefined if not registered.
 */
export function getCapability(agentId) {
    return registry.get(agentId);
}
/**
 * C3: Return agents that match task requirements, sorted descending by fit score.
 *
 * Scoring:
 *   +3  role matches task.role
 *   +2  per ecosystem overlap with task.ecosystems
 *   +1  per filePattern overlap with task.filePatterns
 * Agents with score === 0 are excluded.
 */
export function getCapableAgents(task) {
    const scored = [];
    for (const capability of registry.values()) {
        const score = computeFitScore(capability, task);
        if (score > 0) {
            scored.push({ capability, score });
        }
    }
    scored.sort((a, b) => b.score - a.score);
    return scored.map((s) => s.capability);
}
/**
 * Return all registered capabilities.
 */
export function listCapabilities() {
    return Array.from(registry.values());
}
/**
 * Remove an agent from the registry (useful for testing and cleanup).
 */
export function unregisterCapability(agentId) {
    return registry.delete(agentId);
}
/**
 * Clear all registered capabilities (primarily for testing).
 */
export function clearRegistry() {
    registry.clear();
}
// ---------------------------------------------------------------------------
// Internal helpers
// ---------------------------------------------------------------------------
function computeFitScore(capability, task) {
    let score = 0;
    if (task.role !== undefined && capability.role === task.role) {
        score += 3;
    }
    if (task.ecosystems !== undefined && task.ecosystems.length > 0) {
        for (const eco of task.ecosystems) {
            if (capability.ecosystems.includes(eco)) {
                score += 2;
            }
        }
    }
    if (task.filePatterns !== undefined && task.filePatterns.length > 0) {
        for (const pattern of task.filePatterns) {
            if (capability.filePatterns.includes(pattern)) {
                score += 1;
            }
        }
    }
    return score;
}
//# sourceMappingURL=capability-registry.js.map