#!/usr/bin/env node
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const database_1 = require("../../06-memory/database/database");
const utils_1 = require("./utils");
// Initialize database
(0, database_1.initializeDatabase)();
// Import command modules
const setup_1 = require("./commands/setup");
const scan_1 = require("./commands/scan");
const status_1 = require("./commands/status");
const memory_1 = require("./commands/memory");
const session_1 = require("./commands/session");
const watch_1 = require("./commands/watch");
const branch_1 = require("./commands/branch");
const team_1 = require("./commands/team");
const community_1 = require("./commands/community");
const ci_1 = require("./commands/ci");
const sync_1 = require("./commands/sync");
const dashboard_1 = require("./commands/dashboard");
const chat_repl_1 = require("./commands/chat-repl");
const help_1 = require("./commands/help");
const teach_1 = require("./commands/teach");
const vibe_cli_1 = require("../../06-memory/vibe/vibe-cli");
const cloud_1 = require("./commands/cloud");
const hook_1 = require("./commands/hook");
// Parse arguments
const args = (0, utils_1.parseArgs)(process.argv.slice(2));
const cmd = args[0] || '';
// Command dispatch
switch (cmd) {
    case '--version':
    case '-v':
    case 'version':
        (0, help_1.doVersion)();
        break;
    // Setup
    case 'run':
        (0, setup_1.doRun)(args);
        break;
    case 'start':
        (0, setup_1.doStart)(args);
        break;
    case 'stop':
        (0, setup_1.doStop)();
        break;
    case 'setup':
        (0, setup_1.doSetup)(args).catch((e) => {
            const msg = e instanceof Error ? e.message : String(e);
            console.log(utils_1.C.warn('  Setup crashed: ' + msg));
            process.exit(1);
        });
        break;
    // Scan
    case 'scan':
        (0, scan_1.doScan)(args);
        break;
    case 'analyze':
        (0, scan_1.doAnalyze)(args);
        break;
    case 'blindspots':
        (0, scan_1.doBlindspots)(args);
        break;
    // Status
    case 'status':
        (0, status_1.doStatus)();
        break;
    case 'doctor':
        (0, status_1.doDoctor)().catch((e) => {
            const msg = e instanceof Error ? e.message : String(e);
            console.log(utils_1.C.warn('  Doctor failed: ' + msg));
            process.exit(1);
        });
        break;
    case 'verify':
        (0, status_1.doVerify)();
        break;
    // Memory
    case 'memory':
        (0, memory_1.doMemory)(args);
        break;
    case 'handoff':
        (0, memory_1.doHandoff)(args);
        break;
    case 'replay':
        (0, memory_1.doReplay)(args);
        break;
    case 'continue':
        (0, memory_1.doContinue)();
        break;
    // Session
    case 'session':
        (0, session_1.doSession)(args);
        break;
    case 'context':
        (0, session_1.doContext)(args);
        break;
    case 'decisions':
        (0, session_1.doDecisions)(args);
        break;
    // Watch/Bridge
    case 'watch':
        (0, watch_1.doWatch)(args);
        break;
    case 'install-hook':
        (0, hook_1.doInstallHook)();
        break;
    case 'uninstall-hook':
        (0, hook_1.doUninstallHook)();
        break;
    case 'bridge':
        (0, watch_1.doBridge)(args);
        break;
    case 'watch-editor':
        (0, watch_1.doWatchEditor)(args);
        break;
    // Branch
    case 'branches':
        (0, branch_1.doBranches)();
        break;
    case 'switch-back':
        (0, branch_1.doSwitchBack)(args);
        break;
    case 'lessons':
        (0, branch_1.doLessons)(args);
        break;
    case 'evolution':
        (0, branch_1.doEvolution)(args);
        break;
    case 'focus':
        (0, branch_1.doFocus)(args);
        break;
    case 'why':
        (0, branch_1.doWhy)(args);
        break;
    // Team
    case 'team':
        (0, team_1.doTeam)(args);
        break;
    // Community
    case 'community':
        (0, community_1.doCommunity)(args);
        break;
    // Teach
    case 'teach':
        (0, teach_1.doTeach)(args).catch((e) => {
            const msg = e instanceof Error ? e.message : String(e);
            console.log(utils_1.C.warn('  Teach failed: ' + msg));
            process.exit(1);
        });
        break;
    case 'profile':
        (0, teach_1.doProfile)(args);
        break;
    // CI
    case 'ci':
        (0, ci_1.doCI)(args);
        break;
    // Sync
    case 'sync':
        (0, sync_1.doSync)(args);
        break;
    case 'migrate':
        (0, sync_1.doMigrate)();
        break;
    case 'cross-project':
        (0, sync_1.doCrossProject)(args);
        break;
    // Dashboard
    case 'dashboard':
    case 'dash':
        (0, dashboard_1.doDashboard)();
        break;
    case 'perf':
    case 'performance':
        (0, dashboard_1.doPerf)();
        break;
    // Setup
    case 'mcp-config':
        (0, help_1.doMcpConfig)();
        break;
    // Vibe
    case 'vibe':
        (0, vibe_cli_1.doVibe)(args);
        break;
    // Aliases
    case 'search':
    case 'find':
        (0, memory_1.doMemory)(['memory', 'search', ...args.slice(1)]);
        break;
    case 'events':
    case 'changes':
        (0, watch_1.doWatch)(['watch', 'events', ...args.slice(1)]);
        break;
    case 'list':
    case 'ls':
    case 'packs':
        (0, cloud_1.doCommunityPacks)(args);
        break;
    // Cloud
    case 'cloud':
        (0, cloud_1.doCloud)(args).catch((e) => {
            const msg = e instanceof Error ? e.message : String(e);
            console.log(utils_1.C.warn('  Cloud failed: ' + msg));
        });
        break;
    // REPL
    case 'repl':
    case '-i':
    case '--interactive':
        (0, chat_repl_1.doChatRepl)();
        break;
    // Help
    case 'help':
    case '--help':
    case '-h':
        (0, help_1.doHelp)();
        break;
    default:
        // If no command and TTY → open interactive REPL
        if (!cmd && process.stdin.isTTY) {
            (0, chat_repl_1.doChatRepl)();
        }
        else {
            (0, help_1.doHelp)();
        }
        break;
}
//# sourceMappingURL=cli.js.map