import { Command } from 'commander';
import { resolve } from 'node:path';
import { RegistryClient, readCredentials } from '@expxagents/registry-client';
export const registryInstallCommand = new Command('add')
    .description('Install a squad from the global registry (@scope/name)')
    .argument('<name>', 'Squad name (@scope/name)')
    .option('--version <version>', 'Version or range', 'latest')
    .option('--dir <dir>', 'Target squads directory', './squads')
    .action(async (name, options) => {
    const creds = readCredentials();
    const client = new RegistryClient({
        registryUrl: creds?.registryUrl || 'https://expxagents-marketplace-production.up.railway.app',
        apiKey: creds?.apiKey,
    });
    const targetDir = resolve(options.dir);
    try {
        console.log(`Installing ${name}@${options.version}...`);
        const result = await client.installWithDeps(name, options.version, targetDir);
        console.log(`\u2713 Installed ${result.root}`);
        for (const dep of result.installed) {
            console.log(`  + ${dep.fullName}@${dep.version}`);
        }
    }
    catch (err) {
        console.error(`\u2717 Install failed: ${err.message}`);
        process.exit(1);
    }
});
