"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.TUIClient = void 0;
const fs = __importStar(require("fs-extra"));
const path = __importStar(require("path"));
const tui_chat_1 = require("@mycontext/tui-chat");
const SetupMode_1 = require("./SetupMode");
const AgentChatMode_1 = require("./AgentChatMode");
const registerNextCommands_1 = require("./registerNextCommands");
const ChatFirstController_1 = require("./ChatFirstController");
class TUIClient {
    constructor(projectPath = process.cwd()) {
        this.projectPath = projectPath;
        this.shell = new tui_chat_1.TUIShell(this.projectPath);
    }
    async start() {
        // Register the modes
        const controller = new ChatFirstController_1.ChatFirstController(this.projectPath);
        const setupMode = new SetupMode_1.SetupMode(this.shell, this.projectPath);
        const agentChatMode = new AgentChatMode_1.AgentChatMode(this.shell, this.projectPath, controller);
        this.shell.registerMode(setupMode);
        this.shell.registerMode(agentChatMode);
        // Register next-gen slash commands (features, questions, semantics, impl, ops, history, agents, execute, doctor)
        (0, registerNextCommands_1.registerNextCommands)(this.shell, controller);
        // Register basic exit/help commands
        this.shell.registerCommand({
            command: "exit",
            description: "Exit the TUI Cockpit",
            handler: async () => {
                console.log("\nExiting Specification Cockpit. Goodbye!");
                process.exit(0);
            },
        });
        // Check if context already exists
        const brainPath = path.join(this.projectPath, ".mycontext", "context.json");
        const hasContext = await fs.pathExists(brainPath);
        const defaultMode = hasContext ? "chat" : "setup";
        // Start the TUIShell
        await this.shell.start(defaultMode);
    }
}
exports.TUIClient = TUIClient;
//# sourceMappingURL=TUIClient.js.map