#!/usr/bin/env node
/**
 * Studiograph CLI
 *
 * Main entry point for the studiograph command
 */
import { Command } from 'commander';
import { initCommand } from './commands/init.js';
import { cloneCommand } from './commands/clone.js';
import { pullCommand, pushCommand } from './commands/sync.js';
import { serveCommand } from './commands/serve.js';
import { r2Command } from './commands/r2.js';
import { deployCommand } from './commands/deploy.js';
import { redeployCommand } from './commands/redeploy.js';
import { mcpCommand } from './commands/mcp.js';
import { connectorCommand } from './commands/connector.js';
import { commitCommand } from './commands/commit.js';
import { indexCommand } from './commands/index.js';
import { configCommand } from './commands/config.js';
import { lintCommand } from './commands/lint.js';
import { resetCommand } from './commands/reset.js';
import { orphansCommand } from './commands/orphans.js';
import { aboutCommand } from './commands/about.js';
import { adminCommand } from './commands/admin/index.js';
// Phase D1: `user`, `folder`, `secrets`, `settings`, and `audit` moved
// under `admin`. We keep one release of top-level alias support so
// scripts and muscle memory don't break the day this lands: typing
// `studiograph user list` prints a deprecation banner and re-runs as
// `studiograph admin user list`. The next release drops this shim.
//
// Implemented via argv mangling (rather than registering both Command
// instances) because Commander forbids one Command from having two
// parents — the admin tree is the real home, and a top-level wrapper
// would need a duplicated subcommand surface that immediately rots.
const RELOCATED_COMMANDS = new Set(['user', 'folder', 'secrets', 'settings', 'audit']);
const firstArg = process.argv[2];
if (firstArg && RELOCATED_COMMANDS.has(firstArg)) {
    console.warn(`\x1b[33m\`studiograph ${firstArg}\` has moved to \`studiograph admin ${firstArg}\`. The top-level alias is removed in the next release.\x1b[0m`);
    process.argv.splice(2, 0, 'admin');
}
const program = new Command();
program
    .name('studiograph')
    .description('Team-based AI agent platform with Git-backed knowledge graphs')
    .version('1.0.0');
// Configure custom help to show grouped commands
program.configureHelp({
    sortSubcommands: false,
    // Override the command list formatter to show grouped commands
    formatHelp: (cmd, helper) => {
        const termWidth = helper.padWidth(cmd, helper);
        const itemIndentWidth = 2;
        const itemSeparatorWidth = 2;
        const formatItem = (term, description) => {
            const pad = ' '.repeat(Math.max(0, termWidth - term.length + itemSeparatorWidth));
            return `${' '.repeat(itemIndentWidth)}${term}${pad}${description}`;
        };
        const sections = [
            `Usage: ${helper.commandUsage(cmd)}`,
            '',
            helper.commandDescription(cmd),
            '',
            'Options:',
            ...cmd.options.map(opt => formatItem(helper.optionTerm(opt), helper.optionDescription(opt))),
            formatItem('-h, --help', 'display help for command'),
            '',
            'Getting Started:',
            formatItem('init <team-name> [dir]', 'Initialize a new workspace'),
            formatItem('clone <url> [dir]', 'Clone an existing workspace from a running server'),
            '',
            'Daily Workflow:',
            formatItem('pull', 'Pull latest changes across workspace folders'),
            formatItem('push', 'Push local commits across workspace folders'),
            formatItem('commit', 'Git commit entity changes [--config] [--message]'),
            '',
            'Workspace Management:',
            formatItem('about', 'Display or edit workspace ABOUT.md'),
            formatItem('index', 'Index workspace for search (FTS + semantic)'),
            formatItem('lint', 'Check entity completeness'),
            formatItem('orphans', 'Find entities with zero inbound references'),
            formatItem('config', 'Manage per-server CLI tokens'),
            '',
            'Server & Deployment:',
            formatItem('serve', 'Start HTTP server (Graph API + chat + webhooks)'),
            formatItem('deploy', 'Deploy to Railway'),
            formatItem('redeploy', 'Trigger Railway redeploy'),
            formatItem('admin', 'Owner-only ops (user, folder, secrets, settings, audit, token, migrate, backup, …)'),
            '',
            'Integrations & Extensions:',
            formatItem('mcp', 'MCP server for Claude Desktop'),
            formatItem('connector', 'Manage third-party MCP connectors'),
            formatItem('r2', 'Cloudflare R2 asset storage'),
            '',
            'Maintenance:',
            formatItem('reset <target>', 'Reset entities / sessions / memory / --remote'),
            formatItem('help [command]', 'Display help for command'),
        ];
        return sections.join('\n');
    },
});
// Register commands in grouped order
// Getting Started
program.addCommand(initCommand);
program.addCommand(cloneCommand);
// Daily Workflow
program.addCommand(pullCommand);
program.addCommand(pushCommand);
program.addCommand(commitCommand);
// Workspace Management
program.addCommand(aboutCommand);
program.addCommand(indexCommand);
program.addCommand(lintCommand);
program.addCommand(orphansCommand);
program.addCommand(configCommand);
// Server & Deployment
program.addCommand(serveCommand);
program.addCommand(deployCommand);
program.addCommand(redeployCommand);
program.addCommand(adminCommand);
// Integrations & Extensions
program.addCommand(mcpCommand);
program.addCommand(connectorCommand);
program.addCommand(r2Command);
// Maintenance
program.addCommand(resetCommand);
// Parse arguments
program.parse();
//# sourceMappingURL=index.js.map