"use strict";
/**
 * CommandMate CLI Entry Point
 * Issue #96: npm install CLI support
 */
Object.defineProperty(exports, "__esModule", { value: true });
const commander_1 = require("commander");
const init_1 = require("./commands/init");
const start_1 = require("./commands/start");
const stop_1 = require("./commands/stop");
const status_1 = require("./commands/status");
const issue_1 = require("./commands/issue");
const docs_1 = require("./commands/docs");
// Issue #518: Agent orchestration commands
const ls_1 = require("./commands/ls");
const send_1 = require("./commands/send");
const wait_1 = require("./commands/wait");
const respond_1 = require("./commands/respond");
const capture_1 = require("./commands/capture");
const auto_yes_1 = require("./commands/auto-yes");
// Read version from package.json
// eslint-disable-next-line @typescript-eslint/no-require-imports
const pkg = require('../../package.json');
const program = new commander_1.Command();
program
    .name('commandmate')
    .description('Git worktree management with Claude CLI and tmux sessions')
    .version(pkg.version);
// Init command
program
    .command('init')
    .description('Initialize CommandMate configuration')
    .option('-d, --defaults', 'Use default values (non-interactive)')
    .option('-f, --force', 'Overwrite existing configuration')
    .action(async (options) => {
    await (0, init_1.initCommand)({
        defaults: options.defaults,
        force: options.force,
    });
});
// Start command
// Issue #136: Add --issue and --auto-port flags for worktree support
// Issue #331: Add --auth, --auth-expire, --https, --cert, --key, --allow-http flags
program
    .command('start')
    .description('Start the CommandMate server')
    .option('--dev', 'Start in development mode')
    .option('--daemon', 'Run in background')
    .option('-p, --port <number>', 'Override port number', parseInt)
    .option('-i, --issue <number>', 'Start server for specific issue worktree', parseInt)
    .option('--auto-port', 'Automatically allocate port for worktree server')
    .option('--auth', 'Enable token authentication')
    .option('--auth-expire <duration>', 'Token expiration (e.g., 24h, 7d, 90m)')
    .option('--https', 'Enable HTTPS')
    .option('--cert <path>', 'Path to TLS certificate file')
    .option('--key <path>', 'Path to TLS private key file')
    .option('--allow-http', 'Suppress HTTPS warning when using --auth without certificates')
    .option('--allowed-ips <cidrs>', 'Allowed IP addresses/CIDR ranges (comma-separated)')
    .option('--trust-proxy', 'Trust X-Forwarded-For header from reverse proxy')
    .action(async (options) => {
    await (0, start_1.startCommand)({
        dev: options.dev,
        daemon: options.daemon,
        port: options.port,
        issue: options.issue,
        autoPort: options.autoPort,
        auth: options.auth,
        authExpire: options.authExpire,
        https: options.https,
        cert: options.cert,
        key: options.key,
        allowHttp: options.allowHttp,
        allowedIps: options.allowedIps,
        trustProxy: options.trustProxy,
    });
});
// Stop command
// Issue #136: Add --issue flag for worktree-specific server stop
program
    .command('stop')
    .description('Stop the CommandMate server')
    .option('-f, --force', 'Force stop (SIGKILL)')
    .option('-i, --issue <number>', 'Stop server for specific issue worktree', parseInt)
    .action(async (options) => {
    await (0, stop_1.stopCommand)({
        force: options.force,
        issue: options.issue,
    });
});
// Status command
// Issue #136: Add --issue and --all flags for worktree-specific status
program
    .command('status')
    .description('Show server status')
    .option('-i, --issue <number>', 'Show status for specific issue worktree', parseInt)
    .option('-a, --all', 'Show status for all servers (main + worktrees)')
    .action(async (options) => {
    await (0, status_1.statusCommand)({
        issue: options.issue,
        all: options.all,
    });
});
// Issue #264: issue/docs commands (addCommand pattern for subcommand support)
program.addCommand((0, issue_1.createIssueCommand)());
program.addCommand((0, docs_1.createDocsCommand)());
// Issue #518: Agent orchestration commands [DR1-08] [IA3-07]
// These commands enable CLI-based agent control for worktree operations.
program.addCommand((0, ls_1.createLsCommand)());
program.addCommand((0, send_1.createSendCommand)());
program.addCommand((0, wait_1.createWaitCommand)());
program.addCommand((0, respond_1.createRespondCommand)());
program.addCommand((0, capture_1.createCaptureCommand)());
program.addCommand((0, auto_yes_1.createAutoYesCommand)());
// Issue #264: AI Tool Integration help section
program.addHelpText('after', `
AI Tool Integration:
  Use with Claude Code or Codex to manage issues:
    commandmate issue create --bug --title "Title" --body "Description"
    commandmate issue create --question --title "How to..." --body "Details"
    commandmate docs --section quick-start
`);
// Parse and execute
program.parse();
