export function collectRegisteredTools(extensions) {
    const toolsByName = new Map();
    for (const ext of extensions) {
        for (const tool of ext.tools.values()) {
            if (!toolsByName.has(tool.definition.name)) {
                toolsByName.set(tool.definition.name, tool);
            }
        }
    }
    return Array.from(toolsByName.values());
}
export function findToolDefinition(extensions, toolName) {
    for (const ext of extensions) {
        const tool = ext.tools.get(toolName);
        if (tool) {
            return tool.definition;
        }
    }
    return undefined;
}
export function collectFlags(extensions) {
    const allFlags = new Map();
    for (const ext of extensions) {
        for (const [name, flag] of ext.flags) {
            if (!allFlags.has(name)) {
                allFlags.set(name, flag);
            }
        }
    }
    return allFlags;
}
export function hasExtensionHandlers(extensions, eventType) {
    for (const ext of extensions) {
        const handlers = ext.handlers.get(eventType);
        if (handlers && handlers.length > 0) {
            return true;
        }
    }
    return false;
}
export function findMessageRenderer(extensions, customType) {
    for (const ext of extensions) {
        const renderer = ext.messageRenderers.get(customType);
        if (renderer) {
            return renderer;
        }
    }
    return undefined;
}
export function resolveRegisteredCommands(extensions) {
    const commands = [];
    const counts = new Map();
    for (const ext of extensions) {
        for (const command of ext.commands.values()) {
            commands.push(command);
            counts.set(command.name, (counts.get(command.name) ?? 0) + 1);
        }
    }
    const seen = new Map();
    const takenInvocationNames = new Set();
    return commands.map((command) => {
        const occurrence = (seen.get(command.name) ?? 0) + 1;
        seen.set(command.name, occurrence);
        let invocationName = (counts.get(command.name) ?? 0) > 1 ? `${command.name}:${occurrence}` : command.name;
        if (takenInvocationNames.has(invocationName)) {
            let suffix = occurrence;
            do {
                suffix++;
                invocationName = `${command.name}:${suffix}`;
            } while (takenInvocationNames.has(invocationName));
        }
        takenInvocationNames.add(invocationName);
        return { ...command, invocationName };
    });
}
//# sourceMappingURL=runner-registries.js.map