function normalizeCommandName(name) {
    return name.replace(/^\/+/, '').trim().toLowerCase();
}
export class ACodeCommandRegistry {
    constructor(commands) {
        this.commands = new Map();
        for (const command of commands) {
            this.commands.set(normalizeCommandName(command.name), command);
        }
    }
    list() {
        return [...this.commands.values()];
    }
    expand(input) {
        const match = input.trim().match(/^\/([^\s]+)(?:\s+(.*))?$/s);
        if (!match) {
            return null;
        }
        const command = this.commands.get(normalizeCommandName(match[1] ?? ''));
        if (!command) {
            return null;
        }
        const argumentsText = (match[2] ?? '').trim();
        return {
            command,
            argumentsText,
            prompt: command.body.replace(/\$ARGUMENTS/g, argumentsText),
        };
    }
}
