
import { basename } from '../../../../../base/common/resources.js';

function getCanonicalPluginCommandId(plugin, commandName) {
    const pluginSegment = basename(plugin.uri);
    const prefix = normalizePluginToken(pluginSegment);
    const normalizedCommand = normalizePluginToken(commandName);
    if (normalizedCommand.startsWith(`${prefix}:`)) {
        return normalizedCommand;
    }
    if (prefix === normalizedCommand) {
        return prefix;
    }
    return `${prefix}:${normalizedCommand}`;
}
function normalizePluginToken(value) {
    return value.trim().toLowerCase().replace(/\s+/g, "-").replace(/[^a-z0-9_.:-]/g, "-").replace(/-+/g, "-").replace(/^[-:.]+|[-:.]+$/g, "");
}
class AgentPluginDiscoveryRegistry {
    constructor() {
        this._discovery = [];
    }
    register(descriptor) {
        this._discovery.push(descriptor);
    }
    getAll() {
        return this._discovery;
    }
}
const agentPluginDiscoveryRegistry = ( new AgentPluginDiscoveryRegistry());

export { agentPluginDiscoveryRegistry, getCanonicalPluginCommandId };
