/**
 * studiograph config — slim per-user CLI config helpers.
 *
 * `~/.studiograph/user.json` historically held model provider, model id,
 * API keys, R2 creds, Railway token, etc. Phase 12 moved the workspace-
 * scoped values into the encrypted store; the canonical surface for
 * those is `studiograph settings` / `studiograph secrets`. Phase C6
 * deletes the CLI accessors for them — anyone who needs to set the
 * model provider goes through `studiograph settings`, not here.
 *
 * What's left in user.json that genuinely belongs to the CLI user (not
 * the workspace): the per-server sg_ API tokens minted by `clone` /
 * `admin token issue`. This file's two surviving subcommands list and
 * revoke those.
 *
 * Notable removals (cli-owner-audit §3.6):
 *   - Interactive provider/model picker
 *   - `config set/get/list <key>` generic accessors for model/voyage/etc.
 *   - The MODEL_PROVIDERS dictionary (lived here only for the picker;
 *     setup-wizard.ts has its own copy)
 *
 * If you need the old behavior:
 *   - Set model provider:   studiograph settings set model.provider <name>
 *   - Set model ID:         studiograph settings set model.id <id>
 *   - Set API key:          studiograph secrets set model.<provider>.api_key <key>
 *   - Set Voyage key:       studiograph secrets set voyage.api_key <key>
 */
import { Command } from 'commander';
import { loadUserConfig, saveUserConfig } from '../../core/user-config.js';
export const configCommand = new Command('config').description('Per-server CLI tokens. For workspace settings (model.provider, r2.bucket, …) use `studiograph settings` / `studiograph secrets`.');
configCommand
    .command('list-servers')
    .description('List every server URL with a stored CLI token (token value masked)')
    .action(() => {
    const config = loadUserConfig();
    const tokens = config.studiograph_tokens ?? {};
    const entries = Object.entries(tokens);
    if (entries.length === 0) {
        console.log('No server tokens configured.');
        console.log('Mint one via: studiograph admin token issue <server-url>');
        return;
    }
    console.log(`Configured servers (${entries.length}):\n`);
    for (const [url, token] of entries) {
        // Mask everything after the `sg_` prefix + first 4 hex chars so the
        // token can't be skimmed from a screenshare or pasted log.
        const masked = token.length > 11 ? `${token.slice(0, 7)}…${token.slice(-4)}` : '***';
        console.log(`  ${url.padEnd(40)} ${masked}`);
    }
    console.log();
});
configCommand
    .command('logout <server-url>')
    .description('Drop the stored CLI token for a server (does not revoke it server-side)')
    .action((serverUrl) => {
    const config = loadUserConfig();
    const key = serverUrl.replace(/\/+$/, '');
    if (!config.studiograph_tokens?.[key]) {
        console.error(`No stored token for ${key}.`);
        console.error('Run `studiograph config list-servers` to see what is configured.');
        process.exit(1);
    }
    delete config.studiograph_tokens[key];
    saveUserConfig(config);
    console.log(`Dropped local token for ${key}.`);
    console.log('To also revoke on the server, log into the web UI: Settings → API Tokens.');
});
//# sourceMappingURL=config.js.map